1

I am trying to convert a unix timestamp into a local time using mysql.

The statement I am trying is:

SELECT CONVERT_TZ('FROM_UNIXTIME(table1.timestamp)', 'GMT', 'MET' ),table1.COL2,table1.COL3 WHERE table1ID ='3'

It returns NULL.

I would prefer to do this directly in mysql rather than manipulating the output later using php to keep other parts of my code simple.

Thanks in advance for any help.

4

2 回答 2

2

尝试删除您'FROM_UNIXTIME(table1.timestamp)'喜欢的报价:

SELECT CONVERT_TZ(FROM_UNIXTIME(table1.timestamp), 'GMT', 'MET' ),table1.COL2,table1.COL3 WHERE table1ID ='3'
于 2013-10-03T08:09:03.467 回答
0

周围的引号FROM_UNIXTIME(table1.timestamp)使它成为一个字符串,它看起来不像一个日期。您必须删除引号才能使其成为函数调用。

完成后,您仍然可能会得到NULL. 通过运行测试查询对其进行测试:SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');

如果你仍然得到NULL,你可能需要设置你的时区表。请参阅有关主题的 MySQL 文档

于 2013-10-03T08:15:51.700 回答