Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    [Solved] QDateTime to PostgreSQL

    General and Desktop
    sql postgresql conversion qt 5.5
    3
    5
    3553
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • MrBolton
      MrBolton last edited by MrBolton

      Hi guys,

      imagine the following:
      I've got a widget to enter a date, a time and an integer value to specify the offset from UTC in hours.
      The data set in this widget needs to be saved as a QDateTime and later inserted in a PostgreSQL database column of type "timestamp with timezone".

      What is the best way to construct this QDateTime object with the specified timezone and later construct an insert statement to be executed by the QSqlQuery? I find the topic of timezones and offsets and stuff pretty complicated and can't get my head around what information regarding the timezone is being saved by QDateTime.

      Maybe there's a recommended way for doing this. Any help is highly appreciated!

      Tobi

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You can build your QDateTime with this constructor so you be able to set the offset to the value your user wanted.

        And do the reverse when needed with offsetFromUtc

        Hope it helps

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • MrBolton
          MrBolton last edited by

          Thanks! But which TimeSpec do I pass into the constructor?

          1 Reply Last reply Reply Quote 0
          • M
            mcosta last edited by mcosta

            Hi,

            I suggest to use Qt::UTC when you store data.

            But if you want to use an offset from UTC you should use Qt::OffsetFromUTC with the specified offset

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            1 Reply Last reply Reply Quote 0
            • MrBolton
              MrBolton last edited by

              Thanks, that should do it!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post