Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Date Conversions

Author  Topic 

cardullo4321
Starting Member

40 Posts

Posted - 2012-03-01 : 13:59:44
Can someone help me convert a string format like 10-FEB-12 into a date like 2/10/2012?

Gregory Cardullo

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-01 : 14:04:10

SELECT CONVERT(varchar(25),CONVERT(datetime,'10-FEB-12'),101)

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

cardullo4321
Starting Member

40 Posts

Posted - 2012-03-01 : 14:10:00
Thanks. Do you know how to make it more dynamic where it will automatically convert any string to the date format?

Gregory Cardullo
Go to Top of Page

cardullo4321
Starting Member

40 Posts

Posted - 2012-03-01 : 14:22:13
convert(varchar(25),convert(datetime,(REPLACE([Buy_Date], '-', ' '))),101 ) as DatedAte

Gregory Cardullo
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-01 : 14:23:58
quote:
Originally posted by cardullo4321

convert(varchar(25),convert(datetime,(REPLACE([Buy_Date], '-', ' '))),101 ) as DatedAte

Gregory Cardullo


why are you replacing - characters?
why change it to varchar again?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -