Get a list of dates between two dates

后端 未结 20 2156
醉梦人生
醉梦人生 2020-11-22 00:26

Using standard mysql functions is there a way to write a query that will return a list of days between two dates.

eg given 2009-01-01 and 2009-01-13 it would return

20条回答
  •  旧时难觅i
    2020-11-22 01:06

    CREATE FUNCTION [dbo].[_DATES]
    (
        @startDate DATETIME,
        @endDate DATETIME
    )
    RETURNS 
    @DATES TABLE(
        DATE1 DATETIME
    )
    AS
    BEGIN
        WHILE @startDate <= @endDate
        BEGIN 
            INSERT INTO @DATES (DATE1)
                SELECT @startDate   
        SELECT @startDate = DATEADD(d,1,@startDate) 
        END
    RETURN
    END
    

提交回复
热议问题