January 28, 2019 at 7:06 am
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.
select datefield from Table1
where datefield BETWEEN GETDATE()+31 AND GETDATE() + 61
Thanks
January 28, 2019 at 7:26 am
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.
January 28, 2019 at 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);
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
January 28, 2019 at 9:15 am
Thank you to both of you.
My problem solved .
January 28, 2019 at 9:23 am
Thom A - Monday, January 28, 2019 7:32 AMPersonally 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