I have Database with date field.
I see the time like: 1900-01-01 13:38:00.000
How i can format it like: 13:38
?
By using format code as 106 we can get datetime in “DD MMM YYYY” format. By using format code as 107 we can get datetime in “MMM DD, YYYY” format. By using format code as 108 we can get datetime in “HH:mm: ss” format.
The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format.
We can use DATEPART() function to get the HOUR part of the DateTime in Sql Server, here we need to specify datepart parameter of the DATEPART function as hour or hh.
SELECT convert(varchar, getdate(), 108)
outputs as hh:mm:ss
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With