Re: Perl year

by "Shaun L. Sides" <arch(at)charter.net>

 Date:  Wed, 28 Jun 2000 18:53:48 -0400
 To:  <hwg-techniques(at)mail.hwg.org>
 In-Reply-To:  hwg
  todo: View Thread, Original
-----BEGIN PGP SIGNED MESSAGE-----

On 26 Jan 2037, at 30:208, FODAC(at)aol.com wrote:

> I'm using the localtime function for a date when entries are
> submitted and I'm getting 20100 instead of 2000 for the year. I
> reduced the field size by one and got 205.  This is on a UNIX
> server. Could someone give me a brief explanation of how this
> function works? 

localtime() provides the current year with 1900 subtracted from it.  
Looks like your program is doing:

print "19", $year;

or something like that.  Use this instead:

$year = localtime(time)[5];
$year += 1900;
print $year;

or

$year = localtime(time)[5] + 1900;
print $year;

because TMTOWTDI.

fwiw, I normally initialize localtime() only once at the beginning of 
the prog, since you get a different result each time you initialize the 
function (even if only by a couple of milliseconds).

@now = localtime(time);
$year = $now[5} + 1900;
print $year;

HTH

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.2 -- QDPGP 2.61a
Comment: http://community.wow.net/grt/qdpgp.html

iQCVAwUBOVqB/CEw9uEAOtM/AQE3xwP/TPr/5dc0ngzgy06kh2wJWiYfIoQwolBk
HOLnDlfYrsQ7K15k2LLdEtnLaSJ2qxmimbtgl/1KrtGiQ+2WxU89yr9AGXuRyNQp
qniu8NxRg7YzbiEuUvogY0rL088BmhcOGlCXB/TRnEVecKB2BViOAuh6rW7jbKSb
wDTHod/caCE=
=0eku
-----END PGP SIGNATURE-----

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.