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. SQLite date field
QtWS25 Last Chance

SQLite date field

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 8.0k 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.
  • J Offline
    J Offline
    Jonathan
    wrote on last edited by
    #1

    Not sure if this is really a Qt question or SQLite question.

    Is there any cunning way of identifying a field as a date field as opposed to an integer field?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stukdev
      wrote on last edited by
      #2

      What you mean?
      You want know if a filed is a date or a integer field?

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vsorokin
        wrote on last edited by
        #3

        Three ways for date storing has in SQLite.

        Quote from "this page":http://www.sqlite.org/datatype3.html:

        bq.
        1.2 Date and Time Datatype
        SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
        TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
        REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
        INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
        Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.

        And on "this page":http://www.sqlite.org/lang_datefunc.html described methods for work with date and time.

        --
        Vasiliy

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jonathan
          wrote on last edited by
          #4

          I've created a general purpose programme for creating, managing, and editing arbitrary SQLite databases.

          I'm aware that dates do not have their own storage format. However this makes it hard to decide whether or not a field is a date field. Not knowing makes it difficult to present the correctly formatted data to the user.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stukdev
            wrote on last edited by
            #5

            I'm not sure, but sqlite don't have a struct type of the field at the top of the file of db?

            [quote author="Jonathan" date="1292314669"]I've created a general purpose programme for creating, managing, and editing arbitrary SQLite databases.

            I'm aware that dates do not have their own storage format. However this makes it hard to decide whether or not a field is a date field. Not knowing makes it difficult to present the correctly formatted data to the user.

            [/quote]

            [quote author="Jonathan" date="1292314669"]I've created a general purpose programme for creating, managing, and editing arbitrary SQLite databases.

            I'm aware that dates do not have their own storage format. However this makes it hard to decide whether or not a field is a date field. Not knowing makes it difficult to present the correctly formatted data to the user.

            [/quote]

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dangelog
              wrote on last edited by
              #6

              [quote author="Jonathan" date="1292314669"]I've created a general purpose programme for creating, managing, and editing arbitrary SQLite databases.

              I'm aware that dates do not have their own storage format. However this makes it hard to decide whether or not a field is a date field. Not knowing makes it difficult to present the correctly formatted data to the user.

              [/quote]

              You can't; you can try a best guess, i.e. the column has type TEXT and all the rows are formatted like ISO8601 strings then it's very likely that it contains dates (of course, it is perfectly possible that it simply stores text which "looks like" dates). You can't say anything for INTEGER / REAL types.

              My advice would be simply letting the user choose if a given column is storing dates or numbers/text. :-)

              Software Engineer
              KDAB (UK) Ltd., a KDAB Group company

              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