Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert DateTime.Now into SqlServe adds 2 days to date?

Status
Not open for further replies.

gazzeruk

Programmer
Aug 19, 2003
21
0
0
GB
Hi,

Had this years ago and can't remember how I solved it!

I want to timestamp some events with my own DateTime derived time (not the auto sql TimeStamp!). When I save DateTime.Now into an sql server DateTime field - and view this field, it shows the date+2days and the correct time - why!

Cheers,

Gary
 
OK...

Looked at a bit further and I forgot to mention that I am converting the datetime using the function ToOADate() - which converts a .net DateTime to a double - as apparently required by sql server.

I am guessing that the Date representation in the DateTime starts 2 days behind the OLE DateTime representation and so if I save the following: DateTime.Now.ToOADate()-2 to an sql server DateTime field the correct date is saved.

The above works fine - but is my logic correct!

cheers...

Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top