This is because the localtime function returns 0-based month. ie., 10th month is returned as 9. 1st month is returned as 0, and so on. To fix this, you just have to add 1 to the month.
And another observation is that you are not using sprintf to format your date, which makes it a bit messy.
Have a look at the following simpler version of get date, which uses sprintf to format number with leading 0.
sub Today()
{
my ($day, $month, $year) = (localtime)[3,4,5];
return sprintf "%04d%02d%02d", $year + 1900, $month+1, $day;
}
Your code can be rewritten as
sub getdate {
my ($min, $hr, $day, $mon, $yr) = (localtime($filedate))[1,2,3,4,5];
$filedate = sprintf "%02d-%02d-%04d", $mon+1, $day, $yr+1900;
$filetime = sprintf "%02d:%02d:00", $hr, $min;
}
cheers. Roger
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.