how to ignore DST in MySQL





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















We have a database with flights, and in there, departureTime DATETIME field.



Extra info:



global.time_zone: Europe/Dublin
session.time_zone: Europe/Dublin
MySQL version: 5.7


Problem is, I need to save a flight from China at "2019-03-31 01:00", and server is saving "2019-03-31 02:00" because of the day saving time. In Dublin would be fine, but that flight is from China and should be saved properly.



So what would be the best here?,



Is there any way to ignore DST validations?.



Should I save all datetimes in UTC format and then show them in each timezone?



Should I use timestamp instead of datetime?



If I change server timezone to UTC, what would it happen with old records?










share|improve this question














bumped to the homepage by Community 11 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • datetime manual has a few answers. In general I'd say a system UTC will be helpful. Setting the session timezone before saving a date related.

    – danblack
    Sep 22 '18 at 8:46


















1















We have a database with flights, and in there, departureTime DATETIME field.



Extra info:



global.time_zone: Europe/Dublin
session.time_zone: Europe/Dublin
MySQL version: 5.7


Problem is, I need to save a flight from China at "2019-03-31 01:00", and server is saving "2019-03-31 02:00" because of the day saving time. In Dublin would be fine, but that flight is from China and should be saved properly.



So what would be the best here?,



Is there any way to ignore DST validations?.



Should I save all datetimes in UTC format and then show them in each timezone?



Should I use timestamp instead of datetime?



If I change server timezone to UTC, what would it happen with old records?










share|improve this question














bumped to the homepage by Community 11 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • datetime manual has a few answers. In general I'd say a system UTC will be helpful. Setting the session timezone before saving a date related.

    – danblack
    Sep 22 '18 at 8:46














1












1








1








We have a database with flights, and in there, departureTime DATETIME field.



Extra info:



global.time_zone: Europe/Dublin
session.time_zone: Europe/Dublin
MySQL version: 5.7


Problem is, I need to save a flight from China at "2019-03-31 01:00", and server is saving "2019-03-31 02:00" because of the day saving time. In Dublin would be fine, but that flight is from China and should be saved properly.



So what would be the best here?,



Is there any way to ignore DST validations?.



Should I save all datetimes in UTC format and then show them in each timezone?



Should I use timestamp instead of datetime?



If I change server timezone to UTC, what would it happen with old records?










share|improve this question














We have a database with flights, and in there, departureTime DATETIME field.



Extra info:



global.time_zone: Europe/Dublin
session.time_zone: Europe/Dublin
MySQL version: 5.7


Problem is, I need to save a flight from China at "2019-03-31 01:00", and server is saving "2019-03-31 02:00" because of the day saving time. In Dublin would be fine, but that flight is from China and should be saved properly.



So what would be the best here?,



Is there any way to ignore DST validations?.



Should I save all datetimes in UTC format and then show them in each timezone?



Should I use timestamp instead of datetime?



If I change server timezone to UTC, what would it happen with old records?







mysql datetime timezone






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 20 '18 at 12:30









CyrusCyrus

61




61





bumped to the homepage by Community 11 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 11 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • datetime manual has a few answers. In general I'd say a system UTC will be helpful. Setting the session timezone before saving a date related.

    – danblack
    Sep 22 '18 at 8:46



















  • datetime manual has a few answers. In general I'd say a system UTC will be helpful. Setting the session timezone before saving a date related.

    – danblack
    Sep 22 '18 at 8:46

















datetime manual has a few answers. In general I'd say a system UTC will be helpful. Setting the session timezone before saving a date related.

– danblack
Sep 22 '18 at 8:46





datetime manual has a few answers. In general I'd say a system UTC will be helpful. Setting the session timezone before saving a date related.

– danblack
Sep 22 '18 at 8:46










1 Answer
1






active

oldest

votes


















0














MySQL does not have a datatype that will receive a local time and timezone. You will need to do one of these:




  • Store both fields and worry about interpreting it later.

  • Use application code to convert the time to UTC based on the given TZ. Then store it in a TIMESTAMP while having the system time set to UTC.


When you store 2019-03-31 01:00 into a DATETIME, 2019-03-31 01:00 is the only thing you will ever get from that column.



When you store something in a TIMESTAMP column, it is converted according to MySQL's tz setting, then stored as UTC. When retrieving, it will be reconverted. If nothing has changed, you will get the same value back.



Between 2am and 3am is tricky because that hour repeats once a year. Beware.



If the flight leaves China at 2019-03-31 01:00 China time, but your system is set for Dublin time, neither DATETIME, nor TIMESTAMP will be useful.



Best to convert to/from UTC in your app, then store UTC in the database.






share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f218149%2fhow-to-ignore-dst-in-mysql%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    MySQL does not have a datatype that will receive a local time and timezone. You will need to do one of these:




    • Store both fields and worry about interpreting it later.

    • Use application code to convert the time to UTC based on the given TZ. Then store it in a TIMESTAMP while having the system time set to UTC.


    When you store 2019-03-31 01:00 into a DATETIME, 2019-03-31 01:00 is the only thing you will ever get from that column.



    When you store something in a TIMESTAMP column, it is converted according to MySQL's tz setting, then stored as UTC. When retrieving, it will be reconverted. If nothing has changed, you will get the same value back.



    Between 2am and 3am is tricky because that hour repeats once a year. Beware.



    If the flight leaves China at 2019-03-31 01:00 China time, but your system is set for Dublin time, neither DATETIME, nor TIMESTAMP will be useful.



    Best to convert to/from UTC in your app, then store UTC in the database.






    share|improve this answer




























      0














      MySQL does not have a datatype that will receive a local time and timezone. You will need to do one of these:




      • Store both fields and worry about interpreting it later.

      • Use application code to convert the time to UTC based on the given TZ. Then store it in a TIMESTAMP while having the system time set to UTC.


      When you store 2019-03-31 01:00 into a DATETIME, 2019-03-31 01:00 is the only thing you will ever get from that column.



      When you store something in a TIMESTAMP column, it is converted according to MySQL's tz setting, then stored as UTC. When retrieving, it will be reconverted. If nothing has changed, you will get the same value back.



      Between 2am and 3am is tricky because that hour repeats once a year. Beware.



      If the flight leaves China at 2019-03-31 01:00 China time, but your system is set for Dublin time, neither DATETIME, nor TIMESTAMP will be useful.



      Best to convert to/from UTC in your app, then store UTC in the database.






      share|improve this answer


























        0












        0








        0







        MySQL does not have a datatype that will receive a local time and timezone. You will need to do one of these:




        • Store both fields and worry about interpreting it later.

        • Use application code to convert the time to UTC based on the given TZ. Then store it in a TIMESTAMP while having the system time set to UTC.


        When you store 2019-03-31 01:00 into a DATETIME, 2019-03-31 01:00 is the only thing you will ever get from that column.



        When you store something in a TIMESTAMP column, it is converted according to MySQL's tz setting, then stored as UTC. When retrieving, it will be reconverted. If nothing has changed, you will get the same value back.



        Between 2am and 3am is tricky because that hour repeats once a year. Beware.



        If the flight leaves China at 2019-03-31 01:00 China time, but your system is set for Dublin time, neither DATETIME, nor TIMESTAMP will be useful.



        Best to convert to/from UTC in your app, then store UTC in the database.






        share|improve this answer













        MySQL does not have a datatype that will receive a local time and timezone. You will need to do one of these:




        • Store both fields and worry about interpreting it later.

        • Use application code to convert the time to UTC based on the given TZ. Then store it in a TIMESTAMP while having the system time set to UTC.


        When you store 2019-03-31 01:00 into a DATETIME, 2019-03-31 01:00 is the only thing you will ever get from that column.



        When you store something in a TIMESTAMP column, it is converted according to MySQL's tz setting, then stored as UTC. When retrieving, it will be reconverted. If nothing has changed, you will get the same value back.



        Between 2am and 3am is tricky because that hour repeats once a year. Beware.



        If the flight leaves China at 2019-03-31 01:00 China time, but your system is set for Dublin time, neither DATETIME, nor TIMESTAMP will be useful.



        Best to convert to/from UTC in your app, then store UTC in the database.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 8 '18 at 22:24









        Rick JamesRick James

        43.8k22259




        43.8k22259






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f218149%2fhow-to-ignore-dst-in-mysql%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Liste der Baudenkmale in Friedland (Mecklenburg)

            Single-Malt-Whisky

            Czorneboh