mssql 30 minute time intervals beteen 2 datetime

前端 未结 5 1482
余生分开走
余生分开走 2021-01-25 03:10

I have below query and i want to get datetime in 30 min intervals between 2 datetime. Basicly I got it, but is limitited and wouln\'t return al results if the timediff is over 2

5条回答
  •  滥情空心
    2021-01-25 03:20

    What about this? You can use variables/ fixed values as necessary.

    WITH CTE_Numbers
    AS (
        SELECT n = 1
    
        UNION ALL
    
        SELECT n + 1
        FROM CTE_Numbers
        WHERE n < 100
        )
    SELECT FORMAT(DATEADD(mi, n * 30, '2016/11/03'),'dd-HH:mm')
    FROM CTE_Numbers
    

提交回复
热议问题