Jun 12, 2009

Simple Date Calculation


use POSIX qw(strftime);

$dateStr = strftime "%Y-%m-%d", localtime(time - 48 * 60 * 60);

my $epochYesterday = time - 24 * 60 * 60;

# subtract secs in day from current epoch time

my ($year, $month, $day) = (localtime($epochYesterday))[5,4,3];
$year += 1900;
$month++;