Detect if a date is in Daylight saving time in MySql

前端 未结 4 613
失恋的感觉
失恋的感觉 2021-01-25 09:32

I have inherited a legacy application where all the dates and times are stored in the local timezone (UK). I am not in a position to change how these are stored.

Howeve

4条回答
  •  天涯浪人
    2021-01-25 10:35

    You're in UK. So, your TZ should be CET or CEST (Central Europe Summer Time). You can get the info out this way:

    mysql> SELECT @@system_time_zone;
    +--------------------+
    | @@system_time_zone |
    +--------------------+
    | CEST               |
    +--------------------+
    

    I use this in many of my Stored Procedures. Note: I need both forms of TZ info, whether I need to compute offsets with or without DST being applied.

    CASE @@system_time_zone
      WHEN 'CET'  THEN SET l_tz = 'Europe/Paris';   SET l_tzOff = '+1:00';
      WHEN 'CEST' THEN SET l_tz = 'Europe/Paris';   SET l_tzOff = '+1:00';
      WHEN 'SGT'  THEN SET l_tz = 'Asia/Singapore'; SET l_tzOff = '+8:00';
      ELSE             SET l_tz = 'Europe/Paris';   SET l_tzOff = '+1:00';
    END CASE;
    

    You can get some inspiration from this.

提交回复
热议问题