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 |
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2005-08-24 : 17:42:11
|
| When I use :-select convert(varchar(10),'12/12/2005',101)I get a result of '12/12/2005' but I want the output as '12/12/05'.Please help me with the correct conversion |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-08-24 : 17:55:50
|
Try this:select convert(varchar(10),convert(datetime,'12/12/2005'),1) CODO ERGO SUM |
 |
|
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2005-08-24 : 18:12:11
|
| It works fine....Thanks a lot....Why not this doesn't workselect convert(varchar(10),'12/12/2005',1) as style 1 is without century and it should be 'YY' |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2005-08-24 : 20:43:35
|
quote: Originally posted by sqllearner Why not this doesn't workselect convert(varchar(10),'12/12/2005',1) as style 1 is without century and it should be 'YY'
I'm guessing here... both the source and target datatypes above are VARCHAR. No conversion is necessary. Try changing the style to any style supported, and no conversion occurs. Styles control the conversion of DATETIME to character data types. |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2005-08-24 : 22:05:28
|
| Sam said it.your select convert(varchar(10),'12/12/2005',1) doesn't make any sense because the style only applies to datetime conversions.'12/12/2005' is already varchar(10) so your convert does nothing.This is why Mr Valentine Jones includes a conversion to datetime first, before applying the style conversion.select convert(varchar(10),convert(datetime,'12/12/2005'),1)--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2005-08-25 : 14:14:27
|
| Thanks a lot for the help... |
 |
|
|
|
|
|
|
|