Update:
i am still getting this (4/14/2012 2:44:01 PM) result after trying this
select convert(varchar(30), '4/14/2012 2:44:01 PM',121)
End Update
what format should i use in order to get this result set:
2012-04-14 14:44:01.683
i tried using this but does not show the micro/milli seconds
select convert(varchar(23), '4/14/2012 2:44:01 PM',120)
gets me this result:
4/14/2012 2:44:01 PM
You are very close – in the chapter on CAST and CONVERT on MSDN Books Online, you’ve missed the right answer by one line…. you can use style no. 121 (ODBC canonical (with milliseconds)) to get the result you’re looking for:
This gives me the output of:
Update: based on your updated question – of course this won’t work – you’re converting a string (this:
'4/14/2012 2:44:01 PM'is just a string – it’s NOT a datetime!) to a string……You need to first convert the string you have to a
DATETIMEand THEN convert it back to a string!Try this:
Now you should get:
All zeroes for the milliseconds, obviously, since your original values didn’t include any ….