Hi,
I need help to toggle through dates on a weekly basis to be fed into a script as inputs. The format should be: yyyy/mm/dd (start) yyyy/mm/dd (end), where end date is 7 days increments.
The date (start) would be input as an ARGV and would continue until current date.
I can check current date as follows:
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime time;
$year += 1900;
$mon += 1;
is there any perl function that would toggle through by a week.
And if the Start Date is say Not Sunday, then the start date should be adjusted to the next nearest Sunday.
thank you
Subha
---------- Post updated at 06:57 PM ---------- Previous update was at 12:23 PM ----------
#!/usr/bin/perl -w
use strict;
use warnings;
use Time::Local;
if ($#ARGV < 0)
{
die "Usage dates <input arg> : format is yyyy/mm/dd\n ";
exit (1);
}
my $start_date = $ARGV[0];
my $time = 0;
my $end_time = time;
print "Start Date: $start_date \n";
print "End Date: $end_time \n";
my @dates = split ('/', $start_date);
my $syyyy = $dates[0];
my $smm = $dates[1];
my $sdd = $dates[2];
$smm = $smm - 1;
$time = timelocal(0,0,0,$sdd,$smm,$syyyy);
print "Start time entered:", scalar(localtime($time)), "\n";
while ($time < $end_time)
{
$time += 7 * 24 * 60 * 60;
my ($isec, $imin, $ihour, $idd, $imm, $iyyyy, $iwday, $iyday, $iisdst) = localtime($time);
$iyyyy += 1900;
$imm += 1;
print "Time toggle: $iyyyy $imm $idd \n";
}