generate date list in sql between two given dates
  • we can create list of dates from given date range in sql server by below query .




    Declare @DateFrom datetime
    Declare @DateTo datetime

    Set @DateFrom='2015-07-01'
    Set @DateTo='2015-07-31'

    Declare @Days int
    Declare @Index int

    SET @Index=1
    SET @Days=(SELECT DATEDIFF(dd, @DateFrom, @DateTo)+1)

    declare @TDate table(SNo int, Date Datetime)


    WHILE(@Days>0)
    BEGIN

    Insert Into @TDate(SNo, Date) Values (@Index, DATEADD(dd, @Index-1, @DateFrom))

    SET @Days=@Days-1
    SET @Index=@Index+1
    END

    SELECT * FROM @TDate

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Top Posters Weekly

Optimum Creative