[thelist] Date returning 20100 - second try

CDitty mail at redhotsweeps.com
Thu Jun 29 20:49:13 CDT 2000


Thanks for the detailed explanation, but I didn't create the script this is 
in.  Someone else did over a year ago and I wanted to get it y2k.  I have 
already read up on localtime and understood that, but since I don't know 
perl, I didn't know how to continue.  Anthony was kind enough to give me 
the solution.

All is well now.

At 08:09 PM 6/29/00 , you wrote:
>on Thu, Jun 29, 2000 at 05:51:13PM -0500, CDitty wrote:
> > Haven't seen this come through yet.  Please forgive if this is a dup.
> >
> > Can someone tell me why this routine is returning 20100 instead of 2000?
> >
> > @date = localtime(time);     #puts the current time/date into an array
> > $day = $date[3] + 1;         #have to add 1 since it returns days 
> starting at 0
> > $month = $date[4] + 1;       #same with the month
> > $yr = "20" . $date[5];       #only returns a 2 digit year, change 19 to 20
> > after y2k
> > print "$yr\n";
>
>Because that's how localtime works? Try reading the manual page. The
>struct returned by localtime() contains the following member:
>
>        tm_year
>               The number of years since 1900.
>
>Note that "number of years since 1900" is not, as the comment above
>claims, the two-digit string representing the year. Granted, it's the
>manual page for the localtime C function, not for the Perl localtime,
>However, the perlfunc manpage contains the following bit of useful
>information:
>
>        localtime EXPR
>                Converts a time as returned by the time function
>                to a 9-element array with the time analyzed for
>                the local time zone.  Typically used as follows:
>
>                    #  0    1    2     3     4    5     6     7     8
>                    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> 
>localtime(time);
>
>                All array elements are numeric, and come straight
>                out of a struct tm.  In particular this means that
>                $mon has the range 0..11 and $wday has the range
>                0..6 with sunday as day 0.  Also, $year is the
>                number of years since 1900, that is, $year is 123
>                in year 2023, and not simply the last two digits
>                of the year.  If you assume it is, then you create
>                non-Y2K-compliant programs--and you wouldn't want
>                to do that, would you?
>
>Seems straightforward to me.
>
>Steve
>
>--
>http://a.jaundicedeye.com/weblog/
>because it just annoys people when I talk to myself...
>
>---------------------------------------
>For unsubscribe and other options, including
>the Tip Harvester and archive of TheList go to:
>http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list