Query to get next month's Data

  • Hi,
    I am trying to get the report for the next month , but every month no of days are different .
    Can you please suggest the way to get the report for next month.

    • If we run that query On 3/1 - Report  will show the dates  in April.

    select datefield from Table1
    where  datefield  BETWEEN GETDATE()+31  AND GETDATE() + 61

    Thanks

  • Hi,

    Does this help?


    SELECT datefield FROM Table1 WHERE DateField BETWEEN DATEADD(MONTH, 1, CAST(CAST(MONTH(GETDATE()) AS VARCHAR) + '-01-' + CAST(YEAR(GETDATE()) AS VARCHAR) AS DATETIME)) AND EOMONTH(GETDATE(), 1)

    Thanks.

  • Personally I would go with:

    SELECT YourColumns
    FROM YourTable
    WHERE YourDateColumn >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+1,0)
      AND YourDateColumn < DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+2,0);

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thank you to both of you.
    My problem solved .

  • Thom A - Monday, January 28, 2019 7:32 AM

    Personally I would go with:

    SELECT YourColumns
    FROM YourTable
    WHERE YourDateColumn >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+1,0)
      AND YourDateColumn < DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+2,0);

    I agree with Thom on this one.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply