I've always found that when doing calcuations for things as in your example (eg. things older than x days) it can be easier to leave it in the time format of "seconds since the epoch". This way you can simply get your result by finding anything older than x days (times the number of seconds in those days eg "X" times 24 hours times 60 seconds times 60 seconds.
For example work got me to write a script to purge our share drive everyday of any files older than 7 days. Instead of adjusting times bewtween times formats I read the creation and modified dates for each file and simply compared them to a current time stamp. If the files mod time and creation time where both greater then 7*24*60*60 seconds I delete them.
Its easier to compute things to a base and then work from that base. Seconds is a good base.
If you have time in a mm/dd/yy format push this through the Time::Local() module of Perl to convert it back seconds. This module is the inverse of the localtime() function.
Also the Date::Calc module should blow your hair back as far as date calcuations go.
As for the leading zero try this:
#!perl
$var = 5;
$var = "0".$var if (length($var) < 2);
print $var;
Dean
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.