Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QDateTime to PostgreSQL
QtWS25 Last Chance

[Solved] QDateTime to PostgreSQL

Scheduled Pinned Locked Moved General and Desktop
sqlpostgresqlconversionqt 5.5
5 Posts 3 Posters 4.3k Views
  • 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.
  • MrBoltonM Offline
    MrBoltonM Offline
    MrBolton
    wrote on last edited by MrBolton
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • MrBoltonM Offline
        MrBoltonM Offline
        MrBolton
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by mcosta
          #4

          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
          0
          • MrBoltonM Offline
            MrBoltonM Offline
            MrBolton
            wrote on last edited by
            #5

            Thanks, that should do it!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved