How to convert DDMonYYYY into yy-mm-dd 00:00:00

  • Hi how to convert DDMonYYYY into yy-mm-dd 00:00:00

    Ex: i have date 13MAR2009:00:00:00 in varchar ....i want to convert this into 2009-03-12 00:00:00 format.

    Thanks in advance

  • DECLARE @D VARCHAR(100) = '13MAR2009:00:00:00';

    SELECT CAST(STUFF(STUFF(STUFF(@D, 3, 0, '-'), 7, 0, '-'), 12, 1, ' ') AS DATETIME);

    - 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

  • Thank you very much

  • At the risk of stating the slightly obvious, you will avoid all of these sorts of problems if you store date and time data in appropriate data types. Lord knows there are enough of them in SQL Server 2008 😉

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

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