rockfight
rockfight

Reputation: 1996

How to select unix time stamp from date field in MySQL with different timezone than server?

I have a MySQL server that is in Europe/London timezone and one of my table has a date field. The date is in Asia/Kathmandu timezone. I want to write a select statement to get date field as unix timestamp. Something like SELECT UNIX_TIMESTAMP(FEILD_A) but this will convert FIELD_A to UTC assuming it as Europe/London timezone which is the server's timezone. I want the query to treat the datetime as Asia/Kathmandu timezone and return the timestamp.

Upvotes: 1

Views: 217

Answers (1)

Vasanth
Vasanth

Reputation: 451

Try this one

SELECT CONVERT_TZ(FEILD_A,'GMT','IST');

change IST to your timezone

FEILD_A should be date or timestamp.

Ref: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_convert-tz

Upvotes: 3

Related Questions