cdherold has asked for the wisdom of the Perl Monks concerning the following question:

Brother Monks,

I have another quick question ... how do I get the date as "Wednesday May 31, 2001"?

Right now I have the following code which will give me the numbers, but I want the words.
#local time stamp ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4 +,5,6]; $year=$year+1900; $time = "$hour:$min:$sec"; $date = "$mon-$mday-$year";
thanks,
cdherold

Replies are listed 'Best First'.
Re: Date Retrieval
by rchiav (Deacon) on Apr 19, 2001 at 05:29 UTC
    It's easier than you're making it. Just put localtime in scalar context.

    print scalar localtime;

    Hope this helps..
    Rich

      rich,

      that was exactly what I needed. I'll try not to make it so hard on myself next time.

      thanks,
      cdherold
Re: Date Retrieval
by Eureka_sg (Monk) on Apr 19, 2001 at 05:41 UTC

    First of all, you can use:

    print scalar localtime --> Wed May 31 09:35:38 2001

    If you want a different format, you can check out Date::Calc for more fanciful manipulation, in particular  Date_To_text_long().

Re: Date Retrieval
by Maclir (Curate) on Apr 19, 2001 at 05:38 UTC
    Easy - and look in the "ram" book (perl cookbook).
    1. Use Date::Calc
    2. Do it yourself:
      $thisday = (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,S +unday)[$wday];
    3. </code>
Re: Date Retrieval
by MrNobo1024 (Hermit) on Apr 19, 2001 at 05:39 UTC
    ($sec,$min,$hour,$mday,$mon,$year) = (localtime)[0..5]; $year += 1900; $date = (qw(January February March April May June July August September October November December))[$mon] . " $mday, $year"; print $date;
Re: Date Retrieval
by Tuna (Friar) on Apr 19, 2001 at 06:30 UTC
    Funny you ask. I just learned this yesterday.
    use Date::Calc; $date = UnixDate(ParseDate("today"), "%B %E, %Y");
Re: Date Retrieval
by knobunc (Pilgrim) on Apr 21, 2001 at 00:02 UTC

    Or to control the format a bit more, use POSIX::strftime.

    -ben