February 18, 2010 at 11:57 am
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
February 18, 2010 at 12:00 pm
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
February 18, 2010 at 12:06 pm
Thank you very much
February 20, 2010 at 4:37 am
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 😉
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply