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. General Programming
  3. C#
  4. dates and databases

dates and databases

Scheduled Pinned Locked Moved C#
databasequestion
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 Offline
    R Offline
    Ryan Minor
    wrote on last edited by
    #1

    Hi there I am building some database layer code and trying to be as database independent as possible. One peeve is datetimes. Does it make sense to avoid the use of the datetime objects provided by the database provider altogether and use a double field? Then use persist the dates to the double field using the DateTime.ToOADate method? It seems to me then that I could easily do date comparisons such as "retrieve rows where date > " where the is converted to OA?

    P P D 3 Replies Last reply
    0
    • R Ryan Minor

      Hi there I am building some database layer code and trying to be as database independent as possible. One peeve is datetimes. Does it make sense to avoid the use of the datetime objects provided by the database provider altogether and use a double field? Then use persist the dates to the double field using the DateTime.ToOADate method? It seems to me then that I could easily do date comparisons such as "retrieve rows where date > " where the is converted to OA?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Why not just store the dates as ISO-8801 format?

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      L 1 Reply Last reply
      0
      • R Ryan Minor

        Hi there I am building some database layer code and trying to be as database independent as possible. One peeve is datetimes. Does it make sense to avoid the use of the datetime objects provided by the database provider altogether and use a double field? Then use persist the dates to the double field using the DateTime.ToOADate method? It seems to me then that I could easily do date comparisons such as "retrieve rows where date > " where the is converted to OA?

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Ryan Minor wrote:

        Does it make sense

        No, it doesn't. I use several different database systems and the only problem I've had with DateTimes is that they don't all agree on which range of dates to support. So unless you're storing historical (or far future) data, you probably won't have any trouble.

        L 1 Reply Last reply
        0
        • P Pete OHanlon

          Why not just store the dates as ISO-8801 format?

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          peh. store dates as strings? what's wrong with the existing date and datetime types, they have sufficient support. IMO strings should be avoided for anything that isn't really a string, i.e. numbers, dates, ..., with a possible exception for small binary data encoded with say base64 (when BLOB isn't available or too expensive). and then of course one should use SQLparameters to provide data, not string literals, when querying with e.g. a WHERE clause. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          R P 2 Replies Last reply
          0
          • L Luc Pattyn

            peh. store dates as strings? what's wrong with the existing date and datetime types, they have sufficient support. IMO strings should be avoided for anything that isn't really a string, i.e. numbers, dates, ..., with a possible exception for small binary data encoded with say base64 (when BLOB isn't available or too expensive). and then of course one should use SQLparameters to provide data, not string literals, when querying with e.g. a WHERE clause. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            Luc Pattyn wrote:

            what's wrong with the existing date and datetime types,

            For one, MS SQL Server only supports a subset of DateTime values, so your business layer needs to work around this before you store them in the db.  Note, I'm not advocating store timestamps as strings. /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            1 Reply Last reply
            0
            • L Luc Pattyn

              peh. store dates as strings? what's wrong with the existing date and datetime types, they have sufficient support. IMO strings should be avoided for anything that isn't really a string, i.e. numbers, dates, ..., with a possible exception for small binary data encoded with say base64 (when BLOB isn't available or too expensive). and then of course one should use SQLparameters to provide data, not string literals, when querying with e.g. a WHERE clause. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Except that bubba there wanted to make it db agnostic, and I've worked with a couple of databases in the past that have crap date and time support (hello Ingres, yes I'm talking about you, you malformed piece of relational dataloss crapturd).

              "WPF has many lovers. It's a veritable porn star!" - Josh Smith

              As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

              My blog | My articles | MoXAML PowerToys | Onyx

              L 1 Reply Last reply
              0
              • P Pete OHanlon

                Except that bubba there wanted to make it db agnostic, and I've worked with a couple of databases in the past that have crap date and time support (hello Ingres, yes I'm talking about you, you malformed piece of relational dataloss crapturd).

                "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                My blog | My articles | MoXAML PowerToys | Onyx

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                we could agree on Ingres not being a database then, hence no need to dumb down the whole world and turn agnostic into stupid. Next someone will find a "database" that can't handle real numbers; or strings of more than 6 characters; or Unicode... When he asks "Does it make sense to avoid the use of the datetime objects..." my answer is NO. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                P P 2 Replies Last reply
                0
                • L Luc Pattyn

                  we could agree on Ingres not being a database then, hence no need to dumb down the whole world and turn agnostic into stupid. Next someone will find a "database" that can't handle real numbers; or strings of more than 6 characters; or Unicode... When he asks "Does it make sense to avoid the use of the datetime objects..." my answer is NO. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  Or one that doesn't have operator precedence?

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Ryan Minor wrote:

                    Does it make sense

                    No, it doesn't. I use several different database systems and the only problem I've had with DateTimes is that they don't all agree on which range of dates to support. So unless you're storing historical (or far future) data, you probably won't have any trouble.

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    IMHO adding a non-exhaustive list of those DB systems would turn that into the perfect answer... :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                    P 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      we could agree on Ingres not being a database then, hence no need to dumb down the whole world and turn agnostic into stupid. Next someone will find a "database" that can't handle real numbers; or strings of more than 6 characters; or Unicode... When he asks "Does it make sense to avoid the use of the datetime objects..." my answer is NO. :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      Luc Pattyn wrote:

                      When he asks "Does it make sense to avoid the use of the datetime objects..." my answer is NO.

                      I'd agree with that

                      Luc Pattyn wrote:

                      agree on Ingres not being a database

                      and that.

                      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                      My blog | My articles | MoXAML PowerToys | Onyx

                      L 1 Reply Last reply
                      0
                      • P Pete OHanlon

                        Luc Pattyn wrote:

                        When he asks "Does it make sense to avoid the use of the datetime objects..." my answer is NO.

                        I'd agree with that

                        Luc Pattyn wrote:

                        agree on Ingres not being a database

                        and that.

                        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                        My blog | My articles | MoXAML PowerToys | Onyx

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        Pete O'Hanlon wrote:

                        I'd agree with that and that.

                        I'm glad to see you're back to normal; I suggest you keep ignoring the toaster. :laugh:

                        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                        P 1 Reply Last reply
                        0
                        • L Luc Pattyn

                          Pete O'Hanlon wrote:

                          I'd agree with that and that.

                          I'm glad to see you're back to normal; I suggest you keep ignoring the toaster. :laugh:

                          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #12

                          Luc Pattyn wrote:

                          I suggest you keep ignoring the toaster.

                          I've kicked the hussy out. I only have eyes for the microwave now.

                          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                          My blog | My articles | MoXAML PowerToys | Onyx

                          L 1 Reply Last reply
                          0
                          • P Pete OHanlon

                            Luc Pattyn wrote:

                            I suggest you keep ignoring the toaster.

                            I've kicked the hussy out. I only have eyes for the microwave now.

                            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                            My blog | My articles | MoXAML PowerToys | Onyx

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #13

                            Pete O'Hanlon wrote:

                            I only have eyes for the microwave now

                            I must warn you, microwaves can harm the eyes. And Ray-Ban won't offer adequate protection. :cool:

                            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                            1 Reply Last reply
                            0
                            • L Luc Pattyn

                              IMHO adding a non-exhaustive list of those DB systems would turn that into the perfect answer... :)

                              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                              I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


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

                              Ooookaaay... I'll get right on that.

                              1 Reply Last reply
                              0
                              • R Ryan Minor

                                Hi there I am building some database layer code and trying to be as database independent as possible. One peeve is datetimes. Does it make sense to avoid the use of the datetime objects provided by the database provider altogether and use a double field? Then use persist the dates to the double field using the DateTime.ToOADate method? It seems to me then that I could easily do date comparisons such as "retrieve rows where date > " where the is converted to OA?

                                D Offline
                                D Offline
                                David Skelly
                                wrote on last edited by
                                #15

                                One thing to bear in mind is whether this database will be used for anything else, e.g. accessed directly from reporting tools rather than through your application code. In this case, holding the dates as a double may cause problems for the person writing the reports. Personally, I would consider making the data access layer pluggable, with a separate table gateway[^] for each RDBMS you are going to support. That way, if your database has good date type support you can use it, if not you can fall back on using doubles. Either way, the bulk of your code doesn't know and doesn't care. In fact, you might only need two gateways: one that supports date types and one that doesn't. Then you have a simple configuration switch to flick at deployment time to control how the application stores data. (Actually, that link above isn't the most helpful in the world. Buy the book, it's very good.)

                                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