Search code examples
mysqlpostgresqldatetimetimezonedate-conversion

MySQLs' At Time Zone Convertion


Is there a function in MySQL like in Postgres where I can convert the current timestamp to another timezone?

In Postgres, I do this like these:

 SELECT now() AT TIME ZONE 'PST'

and it converts it on its own. How do I do this in MySQL? is there anyway?

Thanks


Solution

  • I actually solved! HAH!

    Anyway, I used this:

     SELECT CONVERT_TZ(NOW(),SUBSTRING(TIMEDIFF(NOW(), UTC_TIMESTAMP), 1, 6),'-05:00') AS est_timezone
    

    Basically the query interprets as:

    SELECT CONVERT_TZ(NOW(),'-08:00','-05:00') AS est_timezone
    

    I finally got my current timezone which is -08:00 and will convert it to -05:00. This way, I can now proceed with my previous query to making it a VIEW.