Tim Wolak wrote:

Hello all,

I am in need of a quick way to get the current date in the YYYYMMDD format. This is something I would like to understand better on how to get the date with perl. Any suggestions would be most welcome.

Tim

Hi.
You're probably looking for localtime?

> perldoc -f localtime

localtime will return a list with 9 elements.

> ($sec, $min, $hour, $day, $month, $year, $weekday, $dayofyear, $isdst) = localtime(time);

Note that you should add 1900 to $year, because $year is simply the actual year minus 1900 - that was fine during the 20th century, but it might cause errors nowadays.

Read "perldoc -f localtime".

Your program could be:
#!/usr/bin/perl

my ($sec, $min, $hour, $day, $month, $year, $weekday, $dayofyear, $isDST) = localtime(time);
$year += 1900;
print $year, $month, $day;


__END__

Markus Mayr

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to