Archive for the ‘ General ’ Category

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 comment

There 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!

The Beginning

Posted in General on March 5th, 2011 by Frank Park – Be the first to comment

As with anything, there’s always a starting point.. Well.. Here I am! You may find my future blogs to be boring and useless, but my plans are to only post notes that I found either interesting or helpful for whatever I was trying to accomplish at the time. Feel free to contribute!