Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MySQL caculating offset for a time zone

Is there a way in MySQL to calculate the offset for any timezone? For example, to get the local time in the timezone Asia/calcutta. What I want to do is calculate the offset for this timezone and add that offset to GMT to get the local time.

like image 692
Varun Avatar asked Apr 30 '09 06:04

Varun


Video Answer


1 Answers

If you want to calculate the offset of a time zone such as America/Vancouver from UTC you can do it as follows:

SELECT (unix_timestamp() -  unix_timestamp(convert_tz(now(), 'Etc/UTC', 'America/Vancouver'))) / 3600   as offset;

For this to work you will first need to load the time zone information into mysql as outlined here: http://dev.mysql.com/doc/refman/5.0/en/mysql-tzinfo-to-sql.html

like image 134
Kenneth Spencer Avatar answered Oct 11 '22 16:10

Kenneth Spencer