Right now, I know of 3 ways to return the time:
-
CONVERT(varchar, Date, 8) -
CONVERT(varchar, Date, 108) -
CONVERT(time, Date)
What is the difference between #1 and #2, since they return the same answer?
Why does #3 return something that looks different–is it still equivalent to #1/#2’s output?
Are there more ways?
Thanks!
Have a look at the MSDN page for convert. The format
8ishh:mi:ss. If you add100to a format, it uses a four-digit year instead of a two digit year. Since format8is a time format,8and108have the same output.The third option converts a
datetimeto atime. Atimeis not a string and has no format. It’s up to the client how it will be displayed, typically using your local computer’s Regional and Language Settings.