develooper Front page | perl.beginners | Postings from April 2002

RE: Backing up two days from localtime

Thread Previous | Thread Next
Timothy Johnson
April 25, 2002 23:39
RE: Backing up two days from localtime
Message ID:
Actually this is a really common question.  The thing you need to remember
is that when you use localtime(), what you are really saying is
localtime(time).  Local time takes the number of seconds since the year 1970
and translates it into the array you are using UNLESS YOU SPECIFY ANOTHER
DATE IN THE SAME FORMAT.  Therefore you can do this:

localtime(time - (60 * 60 * 24)); #60 sec, 60 min, 24 hrs.

which translates to 

localtime(time - 86400); # the number of seconds in one day, 
                         # which is yesterday.

So taking this info, it is easy to extrapolate that

localtime(time - 86400 * 2);

is the date two days ago. 

Note:  the * operator is calculated before the - operator, otherwise you
would have to use parenthesis to force the operation first.

-----Original Message-----
From: Tara Calishain
Sent: 4/25/02 10:57 PM
Subject: Backing up two days from localtime


I need to back up two days from localtime and I can't figure out how to
it. Currently I'm doing this just so I can work out the rest of the

($day, $month, $year) = (localtime) [3,4,5]; #getting your local time 
$realday = $day-2;
if ($realday<1) {$realday = 30} else {$realday = $day-2};

..... but that's a very cheesy and occasionally wrong workaround.

This is probably a stupid question hopefully not the stupidest question 
you've ever
seen. I hope.



To unsubscribe, e-mail:
For additional commands, e-mail:

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About