I would like to take the Getdate()
results of,
for example
2011-10-05 11:26:55.000
into
11:26:55 AM
I have looked other places and found
Select RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7)
which gives me
11:26AM
It's so close I can taste it!
The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.
The CURRENT_TIMESTAMP function returns the current date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format. Tip: Also look at the GETDATE() function.
To retrieve time as HH:MM format, use the DATE_FORMAT() function. To understand the function and retrieve time, let us create a table. Insert some records in the table using insert command. Display all records from the table using select statement.
select convert(varchar(10), GETDATE(), 108)
returned 17:36:56
when I ran it a few moments ago.
Did you try to make a cast from date to time?
select cast(getdate() as time)
Reviewing the question, I saw the 'AM/PM' at end. So, my answer for this question is:
select format(getdate(), 'hh:mm:ss tt')
Run on Microsoft SQL Server 2012 and Later.
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