note 46354 added to function.date
| From: | post at penest dot no | Date: | Fri, 08 Oct 2004 01:55:48 +0000 |
| Subject: | note 46354 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78156@lists.php.net to get a copy of this message | ||
I needed to change the time to the correct local time for inserting it with now() in a mysql update
query.
i came up with this:
<?php
$nowdate=time();
// this are the correct dst values for norway and chile i fetched from timeanddate.com
$chile_dst_end=mktime(0,0,0,3,14,date("Y"));
$chile_dst_start=mktime(0,0,0,10,10,date("Y"));
// the server is located in norway
$norge_dst_end=mktime(3,0,0,10,31,date("Y"));
$norge_dst_start=mktime(2,0,0,3,28,date("Y"));
//Now it checks that it is in the six hour margin and so on..
if ($nowdate >= $norge_dst_start && $nowdate <= $chile_dst_start) $hourdiff=6;
elseif ($nowdate >= $chile_dst_start && $nowdate <= $norge_dst_end) $hourdiff=5;
elseif ($nowdate >= $chile_dst_end && $nowdate <= $norge_dst_start) $hourdiff=5;
else $hourdiff=4;
// here i substract the amount of hours there are between chile and norway from the current server
time
$query="INSERT INTO table (time) VALUES (DATE_SUB(NOW(), INTERVAL $hourdiff HOUR)) ";
?>
Let me know if it helped you or if there is a better way to do it..
:)
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46354
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46354&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46354&report=yes
Search -- http://master.php.net/manage/user-notes.php