A small variation on the solution offered above would be to use
the inbuilt function time to generate the current date in seconds,
then subtract 10 days (in seconds) from the result (as described above),
and finally put the result into a calendar friendly format using localtime.
You could use strftime (as I have done) to further format the result.
use POSIX qw(strftime);
my $thisday = time;
my $tenDaysPrevious = $thisday - 10*24*60*60;
$tenDaysPrevious = strftime "%m/%d/%Y", (localtime($tenDaysPrevious)); | [reply] |
For that, you're probably going to have to use localtime() and timelocal(). localtime() is a built-in function that takes a time - number of seconds since January first, 1970 - and returns an array that looks like:
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
timelocal() is part of the perl module Time::Local. It does the opposite of localtime, taking an array and returning the number of seconds since 1970. The easiest way I can think of to do what you want would be to extract the day, month, and year from your date, timelocal() it to get a number of seconds, subtract the number of seconds in ten days (10 days * 24 hours * 60 minutes * 60 seconds), then localtime it to get day, month, and year again. Something like this:
$date = (undef, undef, undef, $day, $month, $year);
$tenDaysPrevious = $date - 10*24*60*60;
(undef, undef, undef, $laterDay, $laterMonth, $laterYear) = timelocal($tenDaysPrevious);
See? Easy. | [reply] |
would u help me on finding the yesterday date.I have tried using the use::Format qw(time2str).
And i want to run a file where to generate the data for last month.
Infact all the possible date format i tried are not working.
Please help.
| [reply] |