datetime to totalminute in sql

前端 未结 3 1574
猫巷女王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

    0 讨论(0)
  • 2020-12-17 17:03

    (DATEPART(HOUR,GETDATE()) * 60) + DATEPART(MINUTE,GETDATE())

    0 讨论(0)
  • 2020-12-17 17:05

    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)
    
    0 讨论(0)
提交回复
热议问题