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.
| Author |
Topic |
|
jimdarter
Starting Member
14 Posts |
Posted - 2012-05-15 : 13:52:36
|
| Hi - I've a table that has a date column which has values written in the following format. 201108122011093020110107How can I change the format of the date to make it look something like this (or may be any other date format)2011/08/122011/09/302011/01/07 |
|
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2012-05-15 : 14:00:17
|
| [code]select LEFT('20110812',4)+'/'+SUBSTRING('20110812',5,2)+'/'+right('20110812',2)[/code]Vijay is here to learn something from you guys. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-15 : 21:58:43
|
ideally you should be doing it at front end. However if its not possible you can useSELECT REPLACE(CONVERT(varchar(11),date,121),'-','/') FROM table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-05-16 : 05:11:23
|
| 1 Always use proper DATETIME datatype to store dates2 Use your front end application to do the formationMadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-16 : 05:45:18
|
quote: Originally posted by visakh16
SELECT REPLACE(CONVERT(varchar(11),date,121),'-','/') FROM table
Why not style 111 and get rid of replace function?]SELECT CONVERT(CHAR(10), Date, 111) FROM dbo.Table N 56°04'39.26"E 12°55'05.63" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-05-16 : 06:42:24
|
| If the server is later than 2008, use format functiondeclare @d varchar(8)set @d='20110812'select format(convert(datetime,@d,112),'yyyy/MM/dd')MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|