October 16, 2008 at 12:37 pm
Hi Experts,
How can i convert a varchar field consisting of date values like October 02 2008,December 25 2008 etc to 10-02-2008 and 12-25-2008 .Please help
October 16, 2008 at 12:48 pm
Just use the normal cast, then modify the datetime to fit whatever format you need:
select cast('October 02 2008' as datetime)
The full command is:
select convert(varchar(30),cast('October 02 2008' as datetime),101)
_______________
bkDBA
0.175 seconds -- 10 year average margin of victory at the Daytona 500
212 Degrees
October 16, 2008 at 12:59 pm
Thanks for the quick reply...
Can i use that column name.I want to convert all the values from that column..
October 16, 2008 at 1:02 pm
Yes, you should be able to...but try it out.
In fact, the date doesn't even need to be fully formatted:
select convert(varchar(30),cast('Oct 2 08' as datetime),101)
_______________
bkDBA
0.175 seconds -- 10 year average margin of victory at the Daytona 500
212 Degrees
October 17, 2008 at 6:01 am
How can i execute the same for a particular column.I want to convert all the the values in that particular coulmn
October 17, 2008 at 6:58 am
Ratheesh.K.Nair (10/17/2008)
How can i execute the same for a particular column.I want to convert all the the values in that particular coulmn
select convert(varchar(30),cast(MyLongDateField as datetime),101) from MyTable
_______________
bkDBA
0.175 seconds -- 10 year average margin of victory at the Daytona 500
212 Degrees
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply