Can MySQL convert a stored UTC time to local timezone?

前端 未结 7 1294
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 19:51

Can MySQL convert a stored UTC time to local time-zoned time directly in a normal select statement?

Let\'s say you have some data with a timestamp (UTC).



        
相关标签:
7条回答
  • 2020-12-02 20:26

    One can easily use

    CONVERT_TZ(your_timestamp_column_name, 'UTC', 'your_desired_timezone_name')
    

    For example:

    CONVERT_TZ(timeperiod, 'UTC', 'Asia/Karachi')
    

    Plus this can also be used in WHERE statement and to compare timestamp i would use the following in Where clause:

    WHERE CONVERT_TZ(timeperiod, 'UTC', '{$this->timezone}') NOT BETWEEN {$timeperiods['today_start']} AND {$timeperiods['today_end']}
    
    0 讨论(0)
提交回复
热议问题