note 31133 deleted from function.date by philip
| From: | philip@php.net | Date: | Sat, 02 Aug 2003 15:36:20 +0000 |
| Subject: | note 31133 deleted from function.date by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-53211@lists.php.net to get a copy of this message | ||
Note Submitter: jpoz@quickscribble.com
----
Here is a quick bit of code that will take a unix epoch date (say from a MySQL database) and allow
you to add or subtract the time zone. It will also check to see if the machine (server) is in
daylight savings or not. (This is especially helpful as I am in Missouri, but host some sites in
Arizona, which doesn't do daylight savings).
In this case the Unix epoch time is represented by "date(U)" but could easily be retieved
from a database.
$date123=date(U);
$dst=date(I); //determines whether server is in daylight savings or not, 1=yes, 0=no
if ($dst==1){
$tz="7200"; //7200 seconds = 2 hours
}
else{
$tz="3600"; //3600 seconds = 1 hour
}
$diff=$date123 - $tz; //subtract timezone diff from epoch
echo date("n-j-Y, g:i:s a", $date123);
echo date("n-j-Y, g:i:s a", $diff);
/*
results
4-10-2003, 3:26:39 pm
4-10-2003, 1:26:39 pm
*/