Datetime to totalminute in sql

How can I get the total minute for sql datetime?

Say:

select getdate() from table 

That way I’ll get everything, but I just want to get the full minute. For example, for example, if the time is 07:10:35 , I want 430 .

How to do it?

The value from the field 01-01-2001 07:10:40 I want to get only 430 ((7 * 60) +10).

+7
source share
2 answers

Here is an example:

 DECLARE @dt datetime SET @dt = '01-01-2001 07:10:20' SELECT DATEDIFF(MINUTE, DATEADD(DAY, DATEDIFF(DAY, 0, @dt), 0), @dt) 
+17
source

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 time until midnight. Use the datiff with the mi function to get the number of minutes past midnight.

Use online books for more detailed maths of time and time

+1
source

All Articles