Date conversion problem

  • A developer needs to convert a string 'Thu Aug 5 12:14:49 GMT-0400 2010' into a date format. Does anyone have any suggestions on how this can be done?

  • Something like this?

    DECLARE @t VARCHAR(40)

    SET @t='Thu Aug 5 12:14:49 GMT-0400 2010'

    SELECT CAST(LEFT(STUFF(@t,1,4,''),6) + ' ' + RIGHT(@t,4) + ' '+ LEFT(RIGHT(@t,22),8) AS DATETIME)

    As a side note: the time zone information is ignored assuming it is the same as the system time offset.

    Edit: the concept is rather simple:

    1) remove the weekday, since it's irrelevant

    2) move the year to the proper position (after the day) leading to "mon dd yyyy"

    3) extract the time information and add it to the string leading to "mon dd yyyy hh:mm:ss"



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Perfect! That worked. Thank you so much.

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

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