Hi,
I want to get the current date and time and subtract 1 day to get to the
previous day?
I see timelocal( ) and (time) etc.
How do I code this in PERL to get the previous day?
Thanks
Nurani
Hi,
I want to get the current date and time and subtract 1 day to get to the
previous day?
I see timelocal( ) and (time) etc.
How do I code this in PERL to get the previous day?
Thanks
Nurani
my $minus_one_day = time - 86400;
my $yesterday = localtime $minus_one_day;
print("yesterday: $yesterday \n");
days_ago()
{
# usage: days_ago n
# where n = number of days before today
perl -e '
# take 86400 * # of days from right now in epoch seconds
$yestertime = time - (86400 * $ARGV[0]);
$month = (localtime $yestertime)[4] + 1;
# day of the month
$day = (localtime $yestertime)[3];
# year
$year = (localtime $yestertime)[5] + 1900;
# format mm/dd/yyyy
printf( "%02d/%02d/%d\n", $month, $day, $year); ' $1
}
days_ago 1
This is a shell example, steal what you need for a perl script.