How can I get the total minute for sql datetime?
Let\'s say:
select getdate() from table
In this way, I will get everything, but I
This query will return the number of minutes past midnight.
declare @now datetime = getdate()
declare @midnight datetime = CAST( FLOOR( CAST( @now AS FLOAT ) ) AS DATETIME )
select datediff(mi, @midnight,@now)
The code
CAST( FLOOR( CAST( "yourDateTimeHere" AS FLOAT ) ) AS DATETIME )
converts any datetime to midnight. Use the datediff with the "mi" function to get the number of minutes past midnight.
Use books online for more date and time math
(DATEPART(HOUR,GETDATE()) * 60) + DATEPART(MINUTE,GETDATE())
Here's a sample:
DECLARE @dt datetime
SET @dt = '01-01-2001 07:10:20'
SELECT DATEDIFF(MINUTE, DATEADD(DAY, DATEDIFF(DAY, 0, @dt), 0), @dt)