如何在MySql Select查询中将UTC日期转换为本地时区 [英] How to Convert UTC Date To Local time Zone in MySql Select Query

查看:1007
本文介绍了如何在MySql Select查询中将UTC日期转换为本地时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在MySql数据库查询之一中使用此Where条件.我的问题是我的表中有一个displaytime列,但该表列以UTC Time显示数据.我想在其中转换该displaytime列本地时区.因此,如何从查询本身中提供此功能.

I am using this Where Condition in One Of my query with MySql Database.My Problem is that i have one displaytime column in my table but that table column shows the data in UTC Time.and i want to convert that displaytime column in the Local Time Zone.so how can i provide this facility from query itself.

我已对这些内容进行了仔细检查,因此知道类似SELECT CONVERT_TZ()这样的内容将适用于此功能,但不适用于我.

I have goggled the things and by that i knew that something like SELECT CONVERT_TZ() will work for that.but its not working for me.

这是我需要将显示时间转换为本地时区的查询...所以有人可以指导我吗?

Here is my query in which i need to convert displaytime to local time zone...so can anyone please guide me?

WHERE displaytime >= '2012-12-01 00:00:00'
  AND displaytime <='2013-02-22 23:59:59'
  AND ct.organizationId IN (
    SELECT t.organizationId
      FROM organization_ AS t
      JOIN organization_ AS p ON t.treePath LIKE CONCAT(p.treePath, '%')
     WHERE p.organizationId = 10707

示例DAta

推荐答案

SELECT CONVERT_TZ()将对此起作用,但对我不起作用.

SELECT CONVERT_TZ() will work for that.but its not working for me.

为什么会出现什么错误?

SELECT CONVERT_TZ(displaytime,'GMT','MET');

如果您的列类型是时间戳或日期,则应该工作

should work if your column type is timestamp, or date

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_convert-tz

测试其工作方式:

SELECT CONVERT_TZ(a_ad_display.displaytime,'+00:00','+04:00');

检查您的时区表

SELECT * FROM mysql.time_zone;
SELECT * FROM mysql.time_zone_name;

http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html

如果这些表为空,则您尚未初始化时区表.根据上面的链接,您可以使用mysql_tzinfo_to_sql程序加载时区表.请尝试这个

If those tables are empty, you have not initialized your timezone tables. According to link above you can use mysql_tzinfo_to_sql program to load the Time Zone Tables. Please try this

shell> mysql_tzinfo_to_sql /usr/share/zoneinfo

或如果不起作用,请阅读更多信息: http ://dev.mysql.com/doc/refman/5.5/en/mysql-tzinfo-to-sql.html

or if not working read more: http://dev.mysql.com/doc/refman/5.5/en/mysql-tzinfo-to-sql.html

这篇关于如何在MySql Select查询中将UTC日期转换为本地时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆