datetime to totalminute in sql

前端 未结 3 1578
猫巷女王i
猫巷女王i 2020-12-17 16:08

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

3条回答
  •  独厮守ぢ
    2020-12-17 16:52

    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

提交回复
热议问题