What To Do When convert_tz Returns Null
If you're trying to use the mysql function convert_tz
and it's returning null values:
mysql> select convert_tz(startTime, '+00:00', 'US/Eastern') from table where id = 12;
+-----------------------------------------------+
| convert_tz(startTime, '+00:00', 'US/Eastern') |
+-----------------------------------------------+
| NULL |
+-----------------------------------------------+
1 row in set (0.00 sec)
You need to run the following command on the server to load the timezone information:
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Enter password:
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Then everything will work just fine:
mysql> select convert_tz(startTime, '+00:00', 'US/Eastern') from table where id = 12;
+-----------------------------------------------+
| convert_tz(startTime, '+00:00', 'US/Eastern') |
+-----------------------------------------------+
| 2014-12-13 08:00:00 |
+-----------------------------------------------+
1 row in set (0.06 sec)
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
RSS
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows