Re: DateTime, variants and double
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Wed, 6 Feb 2008 06:32:22 -0500
Geoff Cohen wrote:
I have C++ code that reads a recordset from a table, reading theI would suspect that C++ uses a different seed date than SQL Server. It
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
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"
.
- Follow-Ups:
- Re: DateTime, variants and double
- From: Geoff Cohen
- Re: DateTime, variants and double
- Prev by Date: Re: slow insert a lot of row from table adapter to sql table, improve?
- Next by Date: Re: DateTime, variants and double
- Previous by thread: Re: slow insert a lot of row from table adapter to sql table, improve?
- Next by thread: Re: DateTime, variants and double
- Index(es):
Relevant Pages
|
|