Jump to content

Auto detect daylight savings with query using NOW()


Recommended Posts

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

 

 

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.