note 46354 deleted from function.date by tularis

From: Date: Sun, 30 Jan 2005 14:43:06 +0000
Subject: note 46354 deleted from function.date by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-84224@lists.php.net to get a copy of this message
Note Submitter: post at penest dot no ---- 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.. :)

« previous php.notes (#84224) next »