Finding out Daylight Saving Start and End Dates using MySQL Query
Posted in General on March 21st, 2011 by Frank Park – Be the first to commentThere are very few occasions where you have to purely use MySQL statement to determine if a specified date falls within the daylight saving time. Since the daylight saving time starts on the second Sunday of March and ends on the first Sunday of November, we can write such query to figure out the start and end datetime of the boundary.
SELECT CONCAT(DATE_ADD(CONCAT(YEAR(NOW()), "-03-01"), INTERVAL ((6 - WEEKDAY(CONCAT(YEAR(NOW()), "-03-01"))) + 7) DAY), " 02:00:00") AS dst_start, CONCAT(DATE_ADD(CONCAT(YEAR(NOW()), "-11-01"), INTERVAL ((6 - WEEKDAY(CONCAT(YEAR(NOW()), "-11-01")))) DAY), " 02:00:00") AS dst_end;
With this information, you can now determine if a specific date falls between these two date. This example obviously looks at the current year, but it’s pretty easy to alter the above statement to check any year of your choosing.
Happy coding!
