Home All Groups Group Topic Archive Search About

SELECT statement with milliseconds

Author
2 Mar 2006 11:54 PM
Terri
I expect my select to return data. Why not?

CREATE TABLE #Test
(
testdatetime datetime
)

INSERT INTO #Test
(testdatetime)VALUES ('2006-03-02 14:29:24.000')

SELECT * FROM #Test WHERE testdatetime > '2006-03-02 14:29:23.999'
DROP TABLE #Test

Author
3 Mar 2006 12:17 AM
Roy Harvey
Datetime appears to carry miliseconds to three decimal places, but it
does not quite do that.  The details can be found in the
documentation.  Below is from the 2000 version of Books on Line:

datetime

Date and time data from January 1, 1753 through December 31, 9999, to
an accuracy of one three-hundredth of a second (equivalent to 3.33
milliseconds or 0.00333 seconds). Values are rounded to increments of
..000, .003, or .007 seconds, as shown in the table.

Example            Rounded example
01/01/98 23:59:59.999         1998-01-02 00:00:00.000

01/01/98 23:59:59.995
01/01/98 23:59:59.996
01/01/98 23:59:59.997
01/01/98 23:59:59.998         1998-01-01 23:59:59.997

01/01/98 23:59:59.992
01/01/98 23:59:59.993
01/01/98 23:59:59.994        1998-01-01 23:59:59.993

01/01/98 23:59:59.990
01/01/98 23:59:59.991        1998-01-01 23:59:59.990

Roy Harvey
Beacon Falls, CT


Show quote
On Thu, 2 Mar 2006 16:54:33 -0700, "Terri" <te***@cybernets.com>
wrote:

>I expect my select to return data. Why not?
>
>CREATE TABLE #Test
>(
>testdatetime datetime
>)
>
>INSERT INTO #Test
>(testdatetime)VALUES ('2006-03-02 14:29:24.000')
>
>SELECT * FROM #Test WHERE testdatetime > '2006-03-02 14:29:23.999'
>DROP TABLE #Test
>
>
Author
3 Mar 2006 12:39 AM
Andrew J. Kelly
In addition to what Roy already stated you may find these of interest:



http://www.karaszi.com/SQLServer/info_datetime.asp
Guide to Datetimes
http://www.sqlservercentral.com/columnists/bsyverson/sqldatetime.asp
Datetimes
http://www.murach.com/books/sqls/article.htm
Datetime Searching


--
Andrew J. Kelly  SQL MVP


Show quote
"Terri" <te***@cybernets.com> wrote in message
news:du80jq$8ug$1@reader2.nmix.net...
>I expect my select to return data. Why not?
>
> CREATE TABLE #Test
> (
> testdatetime datetime
> )
>
> INSERT INTO #Test
> (testdatetime)VALUES ('2006-03-02 14:29:24.000')
>
> SELECT * FROM #Test WHERE testdatetime > '2006-03-02 14:29:23.999'
> DROP TABLE #Test
>
>
>
Author
3 Mar 2006 1:19 AM
--CELKO--
The FIPS-127 test suite required at least 5 decimal place in the
seconds.  SQL Server does nto meet the spec, but there are manmy toher
products that do.  You might want to look at DB2, for example, which is
a much more conforming product.

AddThis Social Bookmark Button