mysql utc 查询,如何在MySql Select查询中将UTC日期转换为本地时区

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.

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

3feb5906f95e78a165325c97d5860902.png

SAmple DAta

f4c9ca72420f20a86968911cb839e7d0.png

解决方案SELECT CONVERT_TZ() will work for that.but its not working for me.

Why, what error do you get?

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

should work if your column type is timestamp, or date

Test how this works:

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

Check your timezone-table

SELECT * FROM mysql.time_zone;

SELECT * FROM mysql.time_zone_name;

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值