Re: DateTime, variants and double



Geoff Cohen wrote:
I have C++ code that reads a recordset from a table, reading the
fields into a variable of type _variant_t.
The table has a field of type DateTime which for various reasons I
want to handle in code as a double, which should be possible.
Debugging the code, after reading the datetime field the _variant_t
variable (vt0) is displayed by debug as has having type VT_DATE and
having value 05-02-2008 (DD-MM-YYYY European) which is correct. But
extracting the corresponding double value double dbldt = (double) vt0
gives 39483.0 (this is the dblVal field in the variant).

If I use Query Analyser, and try
SELECT CAST (CAST ('02-05-2008' AS DATETIME) AS FLOAT)
It shows 39481.0
and, to confirm,
SELECT CAST (39481.0 AS DATETIME)
shows 02-05-2008

There is therefore a discrepancy of 2 days between the database value
and the value returned by GetValue()
Note that all times are 00:00 in this example.

Can anyone shed any light on this?
btw I'm using SQL Server 2000 and VC++ 6

I would suspect that C++ uses a different seed date than SQL Server. It
should be easy to verify: cast 0 as a datetime in both systems.

I'm curious why you would not do the conversion in the sql statement used to
retrieve the data ...

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


.



Relevant Pages

  • Re: Select mit IF
    ... > Cast as Datetime) as Einsatzdatum, ... > aeinsatz.pause) as PauMinuten, Cast as ... > AEINSATZ.BKNZARBZEIT as BerechKZ ...
    (microsoft.public.de.sqlserver)
  • Re: DateTime, variants and double
    ... SQL Server stores them as paired integers - see BOL ... The table has a field of type DateTime which for various reasons I ... SELECT CAST AS FLOAT) ... This email account is my spam trap so I ...
    (microsoft.public.data.ado)
  • Re: IF Klausel
    ... > So habe folgenden Select erstellt: ... > Cast as Datetime) as Einsatzdatum, ...
    (microsoft.public.de.sqlserver)
  • Re: DateTime, variants and double
    ... The table has a field of type DateTime which for various reasons I ... SELECT CAST AS FLOAT) ... btw I'm using SQL Server 2000 and VC++ 6 ... This email account is my spam trap so I ...
    (microsoft.public.data.ado)
  • Re: Convert.ToDateTime
    ... and you will need the cast (or the conversion) in order for the code ... If you know that the 16th field is a DateTime, ... or a string which represents a date? ...
    (microsoft.public.dotnet.languages.csharp)