Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to find last sunday (date) using perl? Post 302170723 by joeyg on Tuesday 26th of February 2008 02:39:18 PM
Old 02-26-2008
Hammer & Screwdriver One solution

Here is the script
($dow is the variable for day-of-week, stored at location [6] from localtime)

Code:
> cat sunday
#!/usr/bin/perl

# start of Perl
# Program to find previous Sunday date
#
# use strict;

 $today = date(time);
 $weekend = date2(time);

# start of subroutine date MM-DD-YYYY
sub date 
{
     my($time) = @_;     # incoming parameters

     @when = localtime($time);
     $dow=$when[6];
     $when[5]+=1900;
     $when[4]++;
     $date = $when[4] . "-" . $when[3] . "-" . $when[5];

     return $date;
}

# start of subroutine date2 MM-DD-YYYY
sub date2
{
     my($time) = @_;     # incoming parameters

     $offset = 0;
     $offset = 60*60*24*$dow;
     @when = localtime($time - $offset);
     $when[5]+=1900;
     $when[4]++;
     $date = $when[4] . "-" . $when[3] . "-" . $when[5];

     return $date;
}

print "$today \n";
print "$dow \n";
print "$weekend \n";

Here is the output
Code:
> sunday
2-26-2008 
2 
2-24-2008

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date - Last Sunday thru Saturday

Hi All, I have to kick off a script on every Monday to get some data from database for last week (Sunday thru Saturday). If its Monday (12/12/2005) Begin date will be Sunday - 12/4/2005 End date will be Saturday - 12/10/2005 The script might not kick off on some Mondays. So my... (2 Replies)
Discussion started by: skymirror
2 Replies

2. UNIX for Dummies Questions & Answers

How to find Day of the Week from the given date (Perl)?

How to find the Day of the Week of the given Date using perl? If I have a date in YYY--MM-DD format, how to find the DOW? Based on that, I need to find the following sunday. Pls help. (5 Replies)
Discussion started by: deepakwins
5 Replies

3. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies

4. Shell Programming and Scripting

recurrence for every sunday for Date::MAnip in perl

Hi, I have a requirement to define all Saturdays/Sundays of every month in a year as holidays. I am making use of Date::Manip package available in perl. I tried writing a recurrence as : 0:1*3:7:0:0:0 --> this relation helps me to define 3rd Sunday of a year as sunday. My requirement is... (1 Reply)
Discussion started by: harpreetanand
1 Replies

5. Shell Programming and Scripting

Last sunday of current date

Hi Please help me with this problem i need to find the date of last week sunday from the current given date (12 Replies)
Discussion started by: aishsimplesweet
12 Replies

6. Shell Programming and Scripting

How to derive the last Sunday's date when Current date value is passed

Hi All, I have a requirement in my project where a batch runs on any day of a week. The input files will land to the server every Sunday. I need to read these files based on the current BUS_DAY (which falls any day of the week). For e.g : if the BUS_DAY is 20120308, we need to derive the... (3 Replies)
Discussion started by: dsfreddie
3 Replies

7. Shell Programming and Scripting

How to find last updated date and time of a folder in Perl?

Hi All, I have a process which after some time continues move a files to some folder(say the name of the folder is logdir) What i am trying to do is as the files are coming to the logdir folder, I want the latest updated time and date of the folder in PERL. (1 Reply)
Discussion started by: parthmittal2007
1 Replies

8. Shell Programming and Scripting

Fetch date of 7 years back from current date in Perl

$beginDate = substr(DateCalc("today", "-7Days"),0,8); This fetches the date 7 days back Can I fetch the date before 7 years from todays date in Perl using same syntax Use code tags, see PM. (3 Replies)
Discussion started by: parthmittal2007
3 Replies

9. UNIX for Dummies Questions & Answers

Yesterday's Date if it is Sunday

Hi All, Can you please let me know how to get the yesterday's date of the given date if the given date is Sunday? I can't use GNU. I have the code to get the yesterday's date based on the system date. Thanks (5 Replies)
Discussion started by: shash
5 Replies
PACEMAKER(8)						  System Administration Utilities					      PACEMAKER(8)

NAME
Pacemaker - Part of the Pacemaker cluster resource manager SYNOPSIS
iso8601 command [output modifier] DESCRIPTION
iso8601 - Display and parse ISO8601 dates and times OPTIONS
-?, --help This text -$, --version Version information -V, --verbose Increase debug output Commands: -n, --now Display the current date/time -d, --date=value Parse an ISO8601 date/time. Eg. '2005-01-20 00:30:00 +01:00' or '2005-040' -p, --period=value Parse an ISO8601 date/time with interval/period (wth start time). Eg. '2005-040/2005-043' -D, --duration=value Parse an ISO8601 date/time with duration (wth start time). Eg. '2005-040/P1M' Output Modifiers: -L, --local Show result as a 'local' date/time -O, --ordinal Show result as an 'ordinal' date/time -W, --week Show result as an 'calendar week' date/time For more information on the ISO8601 standard, see: http://en.wikipedia.org/wiki/ISO_8601 AUTHOR
Written by Andrew Beekhof REPORTING BUGS
Report bugs to pacemaker@oss.clusterlabs.org Pacemaker 1.1.7 April 2012 PACEMAKER(8)
All times are GMT -4. The time now is 07:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy