[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Need to create a monthly report and need help with how to get dates or # of days in a month

I need to run a sql query either the first day of the month and look at the previous month or run the last day of the month and look for all days in the current month.
How would I code this?
This is what we are doing now.
WHERE     (Incident.CreatedDateTime >= GETDATE() - 30)
we determine the number of days in the month and run it on the first day of the month manually.
We would like to automate this.
0
FLPeople
Asked:
FLPeople
1 Solution
 
Daniel WilsonCommented:
subtract a month, not a number of days.  Use SQL's DateAdd to do so.

WHERE     (Incident.CreatedDateTime >= DateAdd(m, -1, GETDATE() ) 

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now