0

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

oneofakind
  • 552
  • 17
  • 41
  • SIDE NOTE : `Postgres` instead of `Postgre`, [PostgreSql - Tag Info.](http://stackoverflow.com/tags/postgresql/info) – Vivek S. Feb 27 '15 at 08:32

2 Answers2

0

Use the CONVERT_TZ() for this.

Syntax:

CONVERT_TZ(dt,from_tz,to_tz)

CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value.

Try this:

SELECT CONVERT_TZ(now(),@@session.time_zone,'-08:00');

Here is the reference.

now() -the current time

@@session.time_zone -gives the current time zone(local)

-08:00 -required format in PST.

Ataboy Josef
  • 2,087
  • 3
  • 22
  • 27
0

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.

oneofakind
  • 552
  • 17
  • 41