views:

45

answers:

2

hi

How can I format the following datetime values:

2010-01-21 00:00:00.000 - as - 21/01/2010

and

1900-01-01 09:09:18.000 - as - 09:09:18

+2  A: 

See Cast and convert

e.g.

convert(varchar(50), date_variable, 103 ) -- for the first case
Mark
I think you want style 103, not 101. He wants the day before the month.
Joel Coehoorn
Yes I mis read and edited
Mark
A: 
CASE WHEN Year([DateColumn]) = 1900 THEN CONVERT(varchar(8), [DateColumn], 114)
     ElSE CONVERT(varchar(10), [DateColumn], 103) END
Joel Coehoorn