in reply to help on getting date

Personally, if sorting or comparing human-readable dates is important, I'd recommend YYYY-MM-DD format. It naturally sorts, and reduces ordering confusion about 3 June or 6 January. Bigger units to the left.

As mentioned, localtime() will return the individual components for you. Just remember to add 1 to the month and 1900 to the year.

If your data is already IN the poor MM-DD-YYYY format, then you'll need the help of one of the Date::* modules to convert or compute back to a useful scalar unit like epoch time, Julian dates, or something. Keep dates numeric internally, and provide formatted equivalents only for user presentation.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re: Re: help on getting date
by arturo (Vicar) on Jun 02, 2003 at 18:05 UTC

    First off I want to emphasize that you're right on all the really important points. The nit I will pick is that "need" is kind of a strong word, given that there's a pretty simple way to convert MM-DD-YYYY to YYYY-MM-DD format, even if it's not widely capable like a Date::* module:

    # assumes you have 0-padded dates, but if you don't you can change # the \d\d's to \d\d?'s , and do an appropriate sprintf. my @ymd = map { my ($m, $d, $y) = $_ =~ /(\d\d)-(\d\d)-(\d{4})/; "$y- +$m-$d"; } @dmy;

    HTH

    If not P, what? Q maybe?
    "Sidney Morgenbesser"

      why bother with the temporary variables, especially inside map? Heck, you'd also screen out a small subset of invalid data.
      print  map {$_ =~ /(\d\d)-(\d\d)-(\d{4})/ && "$3-$1-$2"; } ("01-02-1999");
      of course, using this kind of code, you'd need to make sure that your dataset's valid -- you won't get Date::Manip's heavy duty "Am I valid datetime or not" routines.