MusicLovingIndianGirl
MusicLovingIndianGirl

Reputation: 5947

SQL date formatting

I have a datetime column in my table. How to I display only the time?

Say, the value in the column is 2013-03-25 08:40:00.000. How do I display the value 08:40 alone?

Thanks in advance.

Upvotes: 0

Views: 1213

Answers (2)

Himanshu
Himanshu

Reputation: 32612

For SQL Server:

Since you don't want to show only time in hh:mm format you can use this:

SELECT CONVERT(VARCHAR(5), GETDATE(), 8)

For more information see CAST and CONVERT (Transact-SQL)

For MySQL:

SELECT DATE_FORMAT(CURRENT_TIMESTAMP(), '%k:%i')

Upvotes: 0

yogi
yogi

Reputation: 19619

Try this

select Convert(varchar, getdate(), 8)

OR

select SUBSTRING(Convert(varchar, GETDATE(), 8), 1, 5)

If you want only hh:mm

For more date formatting in SQL server see this

Upvotes: 1

Related Questions