Scooby08 Posted March 21, 2010 Share Posted March 21, 2010 I had a query that was selecting the correct data up until daylight savings time a week ago.. Here is it: SELECT * FROM table WHERE (Time_TS BETWEEN NOW() AND NOW() + INTERVAL 24 HOUR) ORDER BY Time_TS Now I need it to select NOW() + 1 hour and I did this: SELECT * FROM table WHERE (Time_TS BETWEEN DATE_ADD(NOW(), INTERVAL 1 HOUR) AND DATE_ADD(NOW(), INTERVAL 1 HOUR) + INTERVAL 24 HOUR) ORDER BY Time_TS My question is can that be written some way to automatically detect when daylight savings is in effect and run the proper query, rather than having to change the code manually when daylight savings hits?? MySQL 5.0.90 Quote Link to comment https://forums.phpfreaks.com/topic/196055-auto-detect-daylight-savings-with-query-using-now/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 21, 2010 Share Posted March 21, 2010 If the time zone database that mysql uses is up to date (which also tells it when the DST start/end dates are) and the time zone setting that is in effect at the time the query is executed is correct (some time zones don't use DST while the one you are in does) and the date/time setting on the server is correct, NOW() should give the correct value. Where is this msyql server running? On a web host somewhere or on a development system? Quote Link to comment https://forums.phpfreaks.com/topic/196055-auto-detect-daylight-savings-with-query-using-now/#findComment-1029764 Share on other sites More sharing options...
Scooby08 Posted March 21, 2010 Author Share Posted March 21, 2010 On a web host somewhere.. Quote Link to comment https://forums.phpfreaks.com/topic/196055-auto-detect-daylight-savings-with-query-using-now/#findComment-1029767 Share on other sites More sharing options...
fenway Posted March 22, 2010 Share Posted March 22, 2010 Unless you use TIMESTAMP columns, time zones in mysql have no effect whatsoever on DATE/DATETIME. Quote Link to comment https://forums.phpfreaks.com/topic/196055-auto-detect-daylight-savings-with-query-using-now/#findComment-1030196 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.