Re: Date function



Sharif Islam wrote:
You can use the Date::Format module.

use strict
use Date::Format;
my $yesterday = time() - ( 24 * 60 * 60 );
my $prefix= time2str("%Y-%m-%d", $yesterday);
# YYYY-MM-DD-RestOfFileName.txt
print $prefix."-RestOfFileName.txt"

Or you can stick to the builtin functions and the standard module Time::Local:

use Time::Local;
my $midnight = timelocal 0, 0, 0, (localtime)[3..5];
my ($d, $m, $y) = (localtime $midnight-40000)[3..5];
print 'Yesterday: ',
sprintf('%d-%02d-%02d', $y+1900, $m+1, $d), "\n";

Note that Sharif's solution doesn't address the DST problem.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages