Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: date

by beebware (Pilgrim)
on Feb 13, 2002 at 16:31 UTC ( #145194=note: print w/ replies, xml ) Need Help??

in reply to Year shows as 20102 in date

#!/usr/bin/perl ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +); $year+=1900; $date = "$month/$mday/$year";

Add the $year+=1900; line, the year is number of years since 1900.
Comment on Re: date
Select or Download Code
Replies are listed 'Best First'.
Re:x2 date (use ISO date formats)
by grinder (Bishop) on Feb 14, 2002 at 16:23 UTC
    Your month value will be off by one (did you test this code?), as the value returned is designed to be used as an offset into an array of month names. Thus, if today is the 14th February 2002, your $date will contain "1/14/2002".

    Where possible, one should try to avoid regional date formatting styles, and use the ISO 8601 norm, to whit, "2002/02/14". The date 2/6/2002 can be parsed as either 2nd of June or 6th of February, depending on which part of the world you live in.

    In Perl 6, this odd behaviour will be corrected, insofar as the year value will be returned as 2002, not 102. Something to keep in mind. Off hand, I remember the month value as also being fixed (hence 2 for February).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://145194]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2016-04-30 02:22 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (441 votes). Check out past polls.