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. VB6 date vs SQL Server date

VB6 date vs SQL Server date

Scheduled Pinned Locked Moved Database
databasesql-servervisual-studiosysadmin
8 Posts 4 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.
  • G Offline
    G Offline
    gpa2000
    wrote on last edited by
    #1

    To simplify date conversion i was adviced to use to integer converted dates i.s.o. the datetime type. Now i have the integer 37954 which resembles 01-12-2003 (dd-mm-yyyy) select cast(37954 as datetime) as startdate But VB6 thinks it is 29-11-2003 ?Format(37954, "dd-mm-yyyy") How is this possible? What am i doing wrong? Grtz, Guus

    M J 2 Replies Last reply
    0
    • G gpa2000

      To simplify date conversion i was adviced to use to integer converted dates i.s.o. the datetime type. Now i have the integer 37954 which resembles 01-12-2003 (dd-mm-yyyy) select cast(37954 as datetime) as startdate But VB6 thinks it is 29-11-2003 ?Format(37954, "dd-mm-yyyy") How is this possible? What am i doing wrong? Grtz, Guus

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      Doing this will give you a major headache. Use the datetime data type. If you need to use date literals, specify them in the ISO format: 'yyyymmdd' (e.g. today would be '20040401'). Stability. What an interesting concept. -- Chris Maunder

      G 1 Reply Last reply
      0
      • G gpa2000

        To simplify date conversion i was adviced to use to integer converted dates i.s.o. the datetime type. Now i have the integer 37954 which resembles 01-12-2003 (dd-mm-yyyy) select cast(37954 as datetime) as startdate But VB6 thinks it is 29-11-2003 ?Format(37954, "dd-mm-yyyy") How is this possible? What am i doing wrong? Grtz, Guus

        J Offline
        J Offline
        jonathan15
        wrote on last edited by
        #3

        Have you tried storing dates as strings? Easy to display in the format you want and easy to convert correctly to date/time format for any calculations that you need to perform on them. Jon

        J 1 Reply Last reply
        0
        • M Mike Dimmick

          Doing this will give you a major headache. Use the datetime data type. If you need to use date literals, specify them in the ISO format: 'yyyymmdd' (e.g. today would be '20040401'). Stability. What an interesting concept. -- Chris Maunder

          G Offline
          G Offline
          gpa2000
          wrote on last edited by
          #4

          Thanks for the good advice but it doesn't answer my question. How is it possible that an integer converted to a date results in two different dates on VB vs SQL Server?

          M 1 Reply Last reply
          0
          • G gpa2000

            Thanks for the good advice but it doesn't answer my question. How is it possible that an integer converted to a date results in two different dates on VB vs SQL Server?

            M Offline
            M Offline
            Mike Dimmick
            wrote on last edited by
            #5

            VB6's built-in dates use OLE's DATE format - an 8-byte floating point number based on 30 December 1899 = 0.0, with the time represented as a fraction. SQL Server's datetime data type is made up of two four-byte signed integers, based on 1 January 1900. The documentation reads: "Values with the datetime data type are stored internally by Microsoft SQL Server as two 4-byte integers. The first 4 bytes store the number of days before or after the base date, January 1, 1900. The base date is the system reference date. Values for datetime earlier than January 1, 1753, are not permitted. The other 4 bytes store the time of day represented as the number of milliseconds after midnight." When converting to and from integers, both VB6 and SQL Server simply use their own internal representations, which is why they produce different values. Stability. What an interesting concept. -- Chris Maunder

            G 1 Reply Last reply
            0
            • M Mike Dimmick

              VB6's built-in dates use OLE's DATE format - an 8-byte floating point number based on 30 December 1899 = 0.0, with the time represented as a fraction. SQL Server's datetime data type is made up of two four-byte signed integers, based on 1 January 1900. The documentation reads: "Values with the datetime data type are stored internally by Microsoft SQL Server as two 4-byte integers. The first 4 bytes store the number of days before or after the base date, January 1, 1900. The base date is the system reference date. Values for datetime earlier than January 1, 1753, are not permitted. The other 4 bytes store the time of day represented as the number of milliseconds after midnight." When converting to and from integers, both VB6 and SQL Server simply use their own internal representations, which is why they produce different values. Stability. What an interesting concept. -- Chris Maunder

              G Offline
              G Offline
              gpa2000
              wrote on last edited by
              #6

              That's the answer i was looking for. Thx! Grtz, Guus

              1 Reply Last reply
              0
              • J jonathan15

                Have you tried storing dates as strings? Easy to display in the format you want and easy to convert correctly to date/time format for any calculations that you need to perform on them. Jon

                J Offline
                J Offline
                Jesse Evans
                wrote on last edited by
                #7

                Hi, jonathan15 I hope you can help me... I store an elapsed time value as a string (mm:ss) in my SQL database. When I query the data from Excel, how can I calculate an average from this data? Would it help if I made the SQL datatype some kind of time value? Thanks in advance for any advice you may provide. 'til next we type... HAVE FUN!! -- Jesse

                J 1 Reply Last reply
                0
                • J Jesse Evans

                  Hi, jonathan15 I hope you can help me... I store an elapsed time value as a string (mm:ss) in my SQL database. When I query the data from Excel, how can I calculate an average from this data? Would it help if I made the SQL datatype some kind of time value? Thanks in advance for any advice you may provide. 'til next we type... HAVE FUN!! -- Jesse

                  J Offline
                  J Offline
                  jonathan15
                  wrote on last edited by
                  #8

                  Jesse, Depends on what you want to do and how you want to get the information into excel really. If you are doing a query to get the raw data into excel and average the results from there you could use something like the following in your Query "select table1.duration, (cast(left(table1.duration,2) as int) *60)+cast((right(table1.duration,2))as int) as seconds from table1" assuming the duration is MM:SS, this will add a field called 'Seconds' which would be a numeric value to your query. it would then be simple to average the seconds using an excel function. Jonathan

                  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