Web Design, Development & Marketing

Web Development Articles

MySQL: Convert a Datetime Value to a Different Time Zone

This is a useful function for MySQL when wanting to change the time zone of a date already stored in your database.

The syntax for the MySQL change time zone function is as follows:

CONVERT_TZ (dt,from_tz,to_tz)

"dt" represents the datetime value, "from_tz" specifies the original time zone, and "to_tz" specifies the time zone to which the datetime value is to be converted.

Some example MySQL queries using the "convert_tz" function are shown below:

SELECT CONVERT_TZ('2006-01-01 13:00:00','GMT','MET');
   -> '2006-01-01 14:00:00'
SELECT CONVERT_TZ('2006-01-01 11:00:00','+00:00','+10:00');
   -> '2006-01-01 21:00:00'

You can find out more about MySQL Date and Time functions at MySQL Date and Time Functions.

Subscribe to RSS Feed Bookmark and Share

Related Links

Related Articles / Posts

Recommended Open Source Invoicing System (25/03/2009)

Recent Recommended Links - October 2008 (03/10/2008)

Recent Recommended Links - April 2008 (11/04/2008)

Recent Recommended Links - March 2008 (16/03/2008)

Tutorial: Importing Excel Data to MySQL using phpMyAdmin (11/05/2007)