Converting a date string to DATETIME

  • I have an interesting conversion issue...

    Run these statements (SQL server 2005):

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.100')

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.101')

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.102')

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.103')

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.104')

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.105')

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.106')

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.107')

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.108')

    SELECT CONVERT(DATETIME, '2009-08-20 12:00:00.109')

    Notice how the last number in the ms doesn't always match - why is that? You can use any time you want - the only thing that matters is the last digit.

  • Because DateTime data type is accurate to 1/300th of a second, not 1/1000th of a second. The definition of the data type in Books Online (or MSDN) explains this and has samples.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply