Reputation: 62746
The SqlServer datetime data type is used to hold timestamps and it is 64 bits long - http://msdn.microsoft.com/en-us/library/ms187819.aspx
I am looking for a sane way to work with it in C++, something in the boost library, probably?
Thanks.
EDIT
I would settle for being able to do these two operations:
2012-01-15 16:54:13.123
2012-01-15 16:54:13.123
into the respective SqlServer datetime value.EDIT2
Here is what I know until now. I have a table with a datetime
column. When I select rows from it, I get this column back with the data type of DBTYPE_DBTIMESTAMP
. According to http://msdn.microsoft.com/en-us/library/ms187819.aspx it should be an 8 byte value, however, I get back a 16 byte value, for instance:
00070015000c07db 00000000001f0007
I could not find any description of this format, but examining it reveals the following structure:
0007 0015 000c 07db 00000000 001f 0007
^ ^ ^ ^ ^ ^
| | | | | |
| | | | | +--- minutes (7)
| | | | +----+--- seconds (31)
| | | +-------------+----+--- year (2011)
| | +----+-------------+----+--- month (12)
| +----+----+-------------+----+--- day (21)
+----+----+----+-------------+----+--- hour (7)
Which corresponds to 2011-12-21 07:07:31
. So, this appears to be easy, but where is the documentation? Are DBTYPE_DBTIMESTAMP
values always reported in this format? Is it SqlSever CE specific or whether the Express and other flavours work the same? Can it contain milliseconds?
BTW, I am using OLEDB to access the database.
Upvotes: 2
Views: 1240
Reputation: 565
Why don't you handle the thing on the side of the sql-server?
You could write a view, which gives you the DBTYPE_DBTIMESTAMP as datetime or varchar back. You could just define, which format you want.
Use the cast()- or convert()- Function
To write back values, you could wirte a little function, also at the sql-server. You could use the function:
Convert(datetime, [value], [format])
Upvotes: 1