djones Posted November 19, 2006 Share Posted November 19, 2006 I moved my host to another company and they are 13 hours ahead. I'm in the east coast of U.S. and the server host is in Perth, Australia. One of my SQL lines needs to be adjusted to allow for the timezone change. This is the current code thats needs to be set to 13 hours behind the now() functiion. Can anyone please help?[code]$sql .= "WHERE text IS NOT NULL AND (y*10000+m*100+d) >= "; $sql .= "(YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) "; // This line needs to be adjusted to my time which is now 13 hours behind[/code] Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/ Share on other sites More sharing options...
printf Posted November 19, 2006 Share Posted November 19, 2006 Use INTERVAL[code]$sql .= "( (YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) - INTERVAL 13 HOUR )";[/code]But I would look at using CONVERT_TZ() instead, surrounding each of your date functions...If you don't want it to return datetime formart...[code]2006-11-18 11:00:00[/code]Then surround the above with with ( expression + 0 )[code]$sql .= "( ( (YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) - INTERVAL 13 HOUR ) + 0 )";[/code]which will return....[code]20061118110000[/code]printf Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127167 Share on other sites More sharing options...
djones Posted November 19, 2006 Author Share Posted November 19, 2006 I'm not getting any results. Here is the full query:$sql = "SELECT id, y, m, d, title, text, start_time, end_time, TIME_FORMAT( start_time, '%l:%i%p' ) AS stime, TIME_FORMAT( end_time, '%l:%i%p' ) AS etime, "; $sql .= "TIME_FORMAT(end_time, '%k:%i') AS etime, " . DB_TABLE_PREFIX . "users.uid, fname, lname "; $sql .= "FROM " . DB_TABLE_PREFIX . "mssgs "; $sql .= "LEFT JOIN " . DB_TABLE_PREFIX . "users "; $sql .= "ON (" . DB_TABLE_PREFIX . "mssgs.uid = " . DB_TABLE_PREFIX . "users.uid) "; $sql .= "WHERE text IS NOT NULL AND (y*10000+m*100+d) >= "; $sql .= "( ( (YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) - INTERVAL 13) )";//OLD LINE $sql .= "(YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) ";$sql .= "ORDER BY y, m, d, start_time limit 6"; This is supposed to list the next 6 upcoming events. ITworks with the OLD line, but not with the correct timezone help Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127179 Share on other sites More sharing options...
fenway Posted November 19, 2006 Share Posted November 19, 2006 *shudder*... y, m and d are what? and what is that ghastly expression with all those NOW()'s doing? Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127191 Share on other sites More sharing options...
printf Posted November 19, 2006 Share Posted November 19, 2006 Your missing the HOUR at the endthis...[code]$sql .= "( ( (YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) - INTERVAL 13) )";[/code]should be...[code]$sql .= "( (YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW())) - INTERVAL 13 HOUR )";[/code]printf Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127197 Share on other sites More sharing options...
djones Posted November 19, 2006 Author Share Posted November 19, 2006 Actually I had that, it was a copy n paste error in the post Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127200 Share on other sites More sharing options...
djones Posted November 19, 2006 Author Share Posted November 19, 2006 @Fenway - Yeah I know. This is an old calendar script. I'm terrible with date functions with any SQL. The y, m and d hold the year, month and day separate for sorting purposes I guess... Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127201 Share on other sites More sharing options...
printf Posted November 19, 2006 Share Posted November 19, 2006 what does (y, m, d) represent?printf Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127203 Share on other sites More sharing options...
djones Posted November 19, 2006 Author Share Posted November 19, 2006 they are fields that hold the year, month and day. Here is sample data:id uid m d y start_time end_time title text1 1 6 24 2004 22:00:00 00:00:00 Dorian Grey - Rhino Dorian Grey @ Rhinoceros Club - 10pm - no cover Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127208 Share on other sites More sharing options...
djones Posted November 19, 2006 Author Share Posted November 19, 2006 I changed it to this and it seems to be working...[code]$sql .= "( (YEAR(NOW())*10000+MONTH(NOW())*100+DAYOFMONTH(NOW() - INTERVAL 13 HOUR)) ) ";[/code] Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127228 Share on other sites More sharing options...
fenway Posted November 20, 2006 Share Posted November 20, 2006 Well, it's great that you got it working, but you should serious considering upgrading that script! Link to comment https://forums.phpfreaks.com/topic/27796-query-with-timezone-adjustments/#findComment-127607 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.