1

I need to find the server timezone, in this form :

UTC: (SIGN)(HOURS):(MINUTES)

My code is :

SELECT 'UTC' || EXTRACT(TIMEZONE_HOURS FROM CURRENT_TIMESTAMP) || ':' || 
EXTRACT(TIMEZONE_MINUTE FROM CURRENT_TIMESTAMP) || '0' AS tz_offest;

But I am still missing the sign (+) or (-) , how can I put the sign?

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
mike
  • 7
  • 3

1 Answers1

0

Try this

SELECT 
CONCAT(
    IF(TIMEDIFF(NOW(), UTC_TIMESTAMP) >= '00:00:00', '+', '-'),
    SUBSTR(TIMEDIFF(NOW(), CONVERT_TZ(NOW(), @@SESSION .time_zone, '+00:00')), 1, 5)
) AS timezone;

Reference answer from How do I get the current time zone of MySQL?

Community
  • 1
  • 1
Wajih
  • 4,227
  • 2
  • 25
  • 40