Balam,

You say your code is not working, but you don't say what's wrong.

You could try Date::Manip. It may be overkill, of course, and you don't get
a Perl date out of Parse_Date; you still need to run it through Unix_Date
with the %s format qualifier. And I always seem to have to hold my tongue
just right to get it to figure out what time zone I'm in. But it's very
flexable, and can handle dates like "2 weeks ago friday".

A much lighter-weight solution would be something like the following:

#!/usr/bin/perl -l
use Time::Local;
foreach my $inp (@ARGV) {
    print "'$inp' is ",
      ($inp =~/\b(\d{1,2})-(\d{1,2})-(\d{4})\b/ &&
            ($val = eval {timelocal (0, 0, 0, $1, $2 - 1, $3)})) ?
      scalar localtime $val : "in error";
    }

Note the change in the regular expression, particularly the change from
(e.g.) "(\d){1,2}" to "(\d{1,2})" to pick up the actual date numbers
correctly, and the "\b" assertion at beginning and end to prevent a match
on (e.g.) "00001-10-2000000". The "eval" around the "timelocal" is because
it croaks on an invalid time.

This is still not COMPLETELY clean - it will accept "31-02-2000", and
interpret it as March 2.

Tom Wyant

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to