Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How to find yesterdays date (was: Date)

by DeaconBlues (Monk)
on Mar 12, 2001 at 08:59 UTC ( [id://63749]=note: print w/replies, xml ) Need Help??


in reply to How to find yesterdays date (was: Date)

Here you go. Sometimes you just have to give them what they want.

my $SECS_IN_A_DAY = 86400; # 60 secs * 60 mins * 24 hrs my ($day, $month, $year) = (localtime(time-$SECS_IN_A_DAY))[3..5]; $month++; $year += 1900; # $month = "0".$month if (length($month) == 1); # for dd-mm-yyyy.txt f +iles. # $day = "0".$day if (length($day) == 1); # for dd-mm-yyyy.txt files. print "File is $day-$month-$year.txt\n";

Replies are listed 'Best First'.
Re: Re: How to find yesterdays date (was: Date)
by dws (Chancellor) on Mar 12, 2001 at 09:14 UTC
    As mentioned over in the Dates thread, this will give you the wrong answer at least one hour a year if you're living in a timezone that switches to and from daylight savings time.

    Update: After some research into this (and an experiment with Time::Local), I'm retracting my claim above, at least for the U.S. We do the timezone switch by either repeating 1am on the first Sunday of April, or by dropping 2am on the last Sunday of October. In either case, determining yesterday's date (but not time) can be done safely by subtracting 24 hours from the current time.

    Subtracing 24 hours will indeed give the wrong answer during a 1 hour window each year in the U.S. if you're in an area that's doing a daylight savings switch.

    Sat Mar 31 22:00:00 2001 < Sun Apr 1 23:00:00 Sat Mar 31 23:00:00 2001 < Mon Apr 2 00:00:00 * Sun Apr 1 00:00:00 2001 < Mon Apr 2 01:00:00

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-16 18:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found