Date from Double

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rushaustin@gmail.com

    #1

    Date from Double

    Hello,
    In SQL, if I do
    Select cast (37797.81597222 22 as datetime)as DateFromDecimal
    i get 2003-06-27 19:34:59.997 as the return.

    in VB.NET if I do:
    Dim idate As Date
    idate = Date.FromOADate (37797.81597222 22)
    I get 6/25/2003 7:35:00 PM as the return.


    Any idea as to why I'm getting different day of the month?

    Any idea how I can get vb.net to return the time in the same precision
    as SQL? VB.net appears to be rounding the time up to 7:35:00 PM

    Thanks!

  • Theo Verweij

    #2
    Re: Date from Double

    1. An SQL DateTime is not an Automation date (the difference is 2 days),
    so to correct for this, add 2 to the double value in VB before
    converting it.

    2. An SQL DateTime has a precision in milliseconds, VB in seconds, so,
    the rounding you mention is correct.




    a VB datetime is stored completely differently than SQL DateTimes, so,
    stored as a double
    rushaustin@gmai l.com wrote:
    Hello,
    In SQL, if I do
    Select cast (37797.81597222 22 as datetime)as DateFromDecimal
    i get 2003-06-27 19:34:59.997 as the return.
    >
    in VB.NET if I do:
    Dim idate As Date
    idate = Date.FromOADate (37797.81597222 22)
    I get 6/25/2003 7:35:00 PM as the return.
    >
    >
    Any idea as to why I'm getting different day of the month?
    >
    Any idea how I can get vb.net to return the time in the same precision
    as SQL? VB.net appears to be rounding the time up to 7:35:00 PM
    >
    Thanks!
    >

    Comment

    • rushaustin@gmail.com

      #3
      Re: Date from Double

      Theo,
      Thank you very much for the reply.

      Theo Verweij wrote:
      1. An SQL DateTime is not an Automation date (the difference is 2 days),
      so to correct for this, add 2 to the double value in VB before
      converting it.
      >
      2. An SQL DateTime has a precision in milliseconds, VB in seconds, so,
      the rounding you mention is correct.
      >
      >
      >
      >
      a VB datetime is stored completely differently than SQL DateTimes, so,
      stored as a double
      rushaustin@gmai l.com wrote:
      Hello,
      In SQL, if I do
      Select cast (37797.81597222 22 as datetime)as DateFromDecimal
      i get 2003-06-27 19:34:59.997 as the return.

      in VB.NET if I do:
      Dim idate As Date
      idate = Date.FromOADate (37797.81597222 22)
      I get 6/25/2003 7:35:00 PM as the return.


      Any idea as to why I'm getting different day of the month?

      Any idea how I can get vb.net to return the time in the same precision
      as SQL? VB.net appears to be rounding the time up to 7:35:00 PM

      Thanks!

      Comment

      Working...