tricky string to DATETIME conversion

  • I have this string date format, cant change it, in an export file..

    1/02/2011 12:03:41 p.m.

    1/02/2011 11:59:00 a.m.

    HOw does one convert this data date time string to TSQL DATETIME ??

    Thanks

  • select

    a.*,

    DT = convert(datetime,replace(a.StrDt,'.',''))

    from

    ( -- Test Data

    select StrDt = '1/02/2011 12:03:41 p.m.'

    union all

    select StrDt = '1/02/2011 11:59:00 a.m.'

    ) a

    Results:

    StrDt DT

    ----------------------- -----------------------

    1/02/2011 12:03:41 p.m. 2011-01-02 12:03:41.000

    1/02/2011 11:59:00 a.m. 2011-01-02 11:59:00.000

  • wow Thanks !:-)

  • Lookup Convert() in Books Online. Using the format codes will assist you greatly.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

Viewing 4 posts - 1 through 3 (of 3 total)

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