I need to know how to make today's date (localtime()) put the day, month and year in a format like: 01.08.04.

I almost have it completed using:

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); ++$mon; my $newyear = $year - 100; $newyear = "0$newyear"; my $todaysdate = join(".", $mday, $mon, $year); print "Today's date is: $todaysdate";
The only problem with this code is I don't get the leading 0 if the day or month is less than 10. For example, today is the 8th of January. This would post 1.08.04 instead of 01.01.04.

Along with that, here's the tough part. I am trying to make an auto-delete with this script for my guestbook so really old messages get deleted when the script is run. Can someone show me how I would compare a date string like 01.08.04 with a different $time?

Ie.: Let's say I wanted to test to see if the date is older than 20 days older than today's date (meaning 20 days ago)

I have an idea on how to go about this using substrings and compare to see if the day is older, but I can't figure out how you would compare a whole string in this format to check for year month AND day. I really only need to calculate how many days ago it was and if it is greater than $autodelete="70" or so, it'll delete.

My question is, how could you do that because if today is the first of January, my method would error the script out trying to subract 70 from 01.

Any ideas on how to get the localtime into this format and check to see if it's too old would be very much appreciated. I made a start, but I think I've bitten off more than I can chew at this point.

Thanks everyone


In reply to Calculating between times by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.