MySQL query for current GMT time

后端 未结 9 1257
你的背包
你的背包 2020-12-24 07:39

This sounds simple enough but I haven\'t been able to figure out how to use a simple SELECT statement to return the current time in GMT.

I have been trying to use CO

相关标签:
9条回答
  • 2020-12-24 08:17

    When the source server timestamp is unknown but the requirement is for a specific tz do this:

    select convert_tz(utc_timestamp(),'+05:00','+00:00')
    

    This uses CST as an example. utc_timestamp will guarantee a '+00:00' result no matter where you query it. The '+05:00' is your desired offset. This works great when hitting multiple unknown servers and it assures you that you returning result will all be in a common tz result set.

    0 讨论(0)
  • 2020-12-24 08:18

    I was searching for my time zone which is GMT+6 (Asia/Dhaka TimeZone)

    MySQL server is in US. The below worked for me.

    SELECT CONVERT_TZ( UTC_TIMESTAMP( ) , '+06:00', '+00:00' )

    0 讨论(0)
  • After seeing all the answers above and seeing it's unreliable to convert to PST, I just used this:

    DATE_SUB(user_last_login, INTERVAL 7 hour)

    0 讨论(0)
提交回复
热议问题