I have let's say
'2015-01-16 13:50:00.000'
in my database.
How do I get the hours and minute only ?
13:50
in the end I want to make query like this
Update A set status = 1 WHERE endTime = current_time()
*endTime = field name of my sample above.
SELECT DATEPART(HOUR, GETDATE());
SELECT DATEPART(MINUTE, GETDATE());
MSDN: DATEPART
I want to get 13:50. is it the way
SELECT CAST(DATEPART(HOUR, GETDATE())AS VARCHAR(2)) + ':' +
CAST(DATEPART(MINUTE, GETDATE())AS VARCHAR(2))
I'm on SQL-Server 2005 which has no TIME
datatype, but this should also work for you:
SELECT LEFT(DATEADD(MINUTE, 10, (CONVERT(TIME(0),GETDATE()))),5)
If you want to filter your records by the hour+minute part:
WHERE DATEPART(HOUR, endTime)= DATEPART(HOUR, GETDATE())
AND DATEPART(MINUTE, endTime)= DATEPART(HOUR, GETDATE())
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