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

RE: Backing up two days from localtime

Thread Previous | Thread Next
From:
Timothy Johnson
Date:
April 25, 2002 23:39
Subject:
RE: Backing up two days from localtime
Message ID:
C0FD5BECE2F0C84EAA97D7300A500D50025813DF@SMILEY
 
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
To: beginners@perl.org
Sent: 4/25/02 10:57 PM
Subject: Backing up two days from localtime

Howdy,

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

($day, $month, $year) = (localtime) [3,4,5]; #getting your local time 
information
$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.

Thanks,

Tara


-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About