faqts : Computers : Programming : Languages : PHP : Function Libraries : Date and Time

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 11 people (55%) answered Yes
Recently 4 of 9 people (44%) answered Yes

Entry

How can I figure the correct date n hours from now while avoiding daylight savings time adjustments?

Jul 6th, 1999 21:43
Leon Atkinson,


The following script adds an hour to the current date.  Note that even 
though the number of seconds exceeds the normal range of 0 to 59, the 
date will be figured correctly by mktime().  If daylight savings time 
happens in the next hour, mktime() will adjust for this as well.
<?
//get current timestamp
list($hour, $min, $sec, $day, $mon, $yr) = 
   explode(" ",date("H i s d m y"));
//print time 3600 seconds (1 hour) from now
print(date(date("H i s d m y"), 
   mktime($hour, $min, $sec+3600, $mon, $day, $yr));
?>