Monday, March 26, 2012

Problems getting Date

Hello there

I have a date value on a sql server database.
When viewing this value using Enterprise Manager Tools it shows the date as 2006-11-23 10:59:52

When i load this value into my webservice object to pass to my handheld device its shows the date as 2006-11-23T10:59:51.6130000-00:00

Im trying to retrieve a date value from my sql server ce 2.0 database.
When i use Query Analyser on the device and view the date it shows 2006-11-23 10:59:51.613000000

Now in my application when i use .ExecuteScalar or .ExecuteReader and reader.GetDate() to retrieve this value it returns 2006-11-23 10:59:51

I need to pass the date from the device to the webservice which will return any records greater than this date but since there is a minute difference in the dates it does not work right....

How can i sort this out?

My only idea is to convert the date being inserted on the device database to be of yyyy-mm-dd hh:mm:ss only

DateTime is not stored as yyyy-mm-dd or as MM-DD-YY or whatever other string representations of the date and time there are.

Here's what date time really is (http://msdn2.microsoft.com/en-us/library/ms172424.aspx):

Date and time data from January 1, 1753, to December 31, 9999, with an accuracy of one three-hundredth second, or 3.33 milliseconds. Values are rounded to increments of .000, .003, or .007 milliseconds.

Stored as two 4-byte integers. The first 4 bytes store the number of days before or after the base date, January 1, 1900. The base date is the system's reference date. Values for datetime earlier than January 1, 1753, are not permitted. The other 4 bytes store the time of day represented as the number of milliseconds after midnight. Seconds have a valid range of 0–59.

My point is: these dates of yours are the same, just printed and rounded differently. I’m assuming you mean a second difference, not minute - note EM rounds 1.6 second to 2 resulting in 10:59:52 while printing it on device results in 10:59.51 with .6 second been truncated.

sql

No comments:

Post a Comment