Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Validate Date Time value on Sqlite before insert / update

Validate Date Time value on Sqlite before insert / update

Scheduled Pinned Locked Moved Database
sqlitequestionannouncement
15 Posts 6 Posters 0 Views 1 Watching
  • 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.
  • R rahmat1985

    as we all know that the correct format for date and time data in sqlite is : 2014-06-18 01:00:00 my question : is there any method to validate date and time data before insert / update on sqlite, maybe when making table, to make sure date and time data is correct, thanks

    J Offline
    J Offline
    jschell
    wrote on last edited by
    #6

    Steps: Choose the data type that it is actually going to be stored as. Take a value and use on of the sqllite functions to convert it to a different type. Take that value and convert it back to the original type. If they are the same then it is valid. So if you start with text, convert it to a number, then convert the number back to text and compare the original text and the final text.

    1 Reply Last reply
    0
    • L Lost User

      Mycroft Holmes wrote:

      You should be storing the data as a datetime TYPE not a string

      SQLite does not have a DATETIME datatype. I'd recommend storing it as an integer, as recommend on their website[^].

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #7

      Eddy Vluggen wrote:

      SQLite does not have a DATETIME datatype

      Now that I did not know.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • L Lost User

        Mycroft Holmes wrote:

        You should be storing the data as a datetime TYPE not a string

        SQLite does not have a DATETIME datatype. I'd recommend storing it as an integer, as recommend on their website[^].

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #8

        Eddy Vluggen wrote:

        SQLite does not have a DATETIME datatype

        Hard to believe, but true. Poor guys who have to deal with such crap!

        L P 2 Replies Last reply
        0
        • B Bernhard Hiller

          Eddy Vluggen wrote:

          SQLite does not have a DATETIME datatype

          Hard to believe, but true. Poor guys who have to deal with such crap!

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #9

          Bernhard Hiller wrote:

          Hard to believe, but true. Poor guys who have to deal with such crap!

          I prefer this crap over SqlCe, MS Access, XML and Excel as a single-file database. A DateTime is usually merely a double; a boolean is usually merely a bit. SQLite is lightweight; you won't find a XML, GUID nor a Spatial datatype either - because all those types can be derived from what is already there. The only thing that seemed weird is that the bool is associated with a numeric type, and not an integer-type.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          P 1 Reply Last reply
          0
          • B Bernhard Hiller

            Eddy Vluggen wrote:

            SQLite does not have a DATETIME datatype

            Hard to believe, but true. Poor guys who have to deal with such crap!

            P Online
            P Online
            PIEBALDconsult
            wrote on last edited by
            #10

            Bernhard Hiller wrote:

            have to deal with such crap

            Seems a choice to me.

            You'll never get very far if all you do is follow instructions.

            1 Reply Last reply
            0
            • L Lost User

              Bernhard Hiller wrote:

              Hard to believe, but true. Poor guys who have to deal with such crap!

              I prefer this crap over SqlCe, MS Access, XML and Excel as a single-file database. A DateTime is usually merely a double; a boolean is usually merely a bit. SQLite is lightweight; you won't find a XML, GUID nor a Spatial datatype either - because all those types can be derived from what is already there. The only thing that seemed weird is that the bool is associated with a numeric type, and not an integer-type.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              P Online
              P Online
              PIEBALDconsult
              wrote on last edited by
              #11

              I'll stick with SqlCe when given a choice; better to have features I don't use than miss features I want. And have you looked at Sql Server LocalDB?

              You'll never get very far if all you do is follow instructions.

              L 1 Reply Last reply
              0
              • R rahmat1985

                as we all know that the correct format for date and time data in sqlite is : 2014-06-18 01:00:00 my question : is there any method to validate date and time data before insert / update on sqlite, maybe when making table, to make sure date and time data is correct, thanks

                P Online
                P Online
                PIEBALDconsult
                wrote on last edited by
                #12

                rahmat1985 wrote:

                as we all know

                We don't all know that.

                You'll never get very far if all you do is follow instructions.

                1 Reply Last reply
                0
                • P PIEBALDconsult

                  I'll stick with SqlCe when given a choice; better to have features I don't use than miss features I want. And have you looked at Sql Server LocalDB?

                  You'll never get very far if all you do is follow instructions.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #13

                  PIEBALDconsult wrote:

                  And have you looked at Sql Server LocalDB?

                  I tried, but failed at downloading[^] it.

                  PIEBALDconsult wrote:

                  I'll stick with SqlCe when given a choice; better to have features I don't use than miss features I want.

                  So you'll be replacing all those SqlCe's with Sql-express versions? SqlCe and SQLite are a close match; but I like to run my code as well on my OpenSUSE desktop and there's no SqlCe there :)

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                  P 1 Reply Last reply
                  0
                  • L Lost User

                    PIEBALDconsult wrote:

                    And have you looked at Sql Server LocalDB?

                    I tried, but failed at downloading[^] it.

                    PIEBALDconsult wrote:

                    I'll stick with SqlCe when given a choice; better to have features I don't use than miss features I want.

                    So you'll be replacing all those SqlCe's with Sql-express versions? SqlCe and SQLite are a close match; but I like to run my code as well on my OpenSUSE desktop and there's no SqlCe there :)

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                    P Online
                    P Online
                    PIEBALDconsult
                    wrote on last edited by
                    #14

                    Eddy Vluggen wrote:

                    replacing all those SqlCe's with Sql-express versions

                    No. The other way around. :-D I use Express for a few things, but for one of my projects I wanted to be able to have the app on a flash drive and not require a server/service/daemon running. That way it can be carried around and used whereever. So now I allow the app to use Ce or regular Sql Server, whichever the user wants to use. All the tables and SQL statements are the same (including DATEs and GUIDs), only the Provider is different.

                    You'll never get very far if all you do is follow instructions.

                    L 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Eddy Vluggen wrote:

                      replacing all those SqlCe's with Sql-express versions

                      No. The other way around. :-D I use Express for a few things, but for one of my projects I wanted to be able to have the app on a flash drive and not require a server/service/daemon running. That way it can be carried around and used whereever. So now I allow the app to use Ce or regular Sql Server, whichever the user wants to use. All the tables and SQL statements are the same (including DATEs and GUIDs), only the Provider is different.

                      You'll never get very far if all you do is follow instructions.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #15

                      ..and might even work relative happily using a different provider[^] on a Raspberry Pi :-D

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups