CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
time

 



frenchface
User

May 28, 2008, 6:58 PM

Post #1 of 2 (1700 views)
time Can't Post

I've looked online several places but I cant figure out how to add and subtract time. Such as its it 8:00 and you want to subtract 8 hours so it would be 23:00. Can someone help me get started?


KevinR
Veteran


May 29, 2008, 12:30 AM

Post #2 of 2 (1676 views)
Re: [frenchface] time [In reply to] Can't Post

the easiset way to add or subtract time is using the epoch. If you do this:


Code
   

print time;



the return value is the epoch, which is the number of seconds since a certain date in the past, which is a little different for different computers but that does not matter for adding or subtracting small amounts of time from the current time. To subtract one hour:


Code
   

$time = time - 3600;



Why 3600? Becuase that is the number of seconds in one hour: 60 seconds X 60 minutes X 1 hour.

To subtract 8 hours just multiply 3600 by 8:




Code
   

$time = time - (3600 * 8);

print scalar localtime($time);

-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives