• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Checking for a date that is within the prior month that I am running

I am running a report and I would like to check DATEA  is within the prior month that I am running?

Example:   If I run the report on October 9, I would like to select all records that DATEA is in September.

What would the syntax be in an MSSQL query using getdate() as today's date?
1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
to get the start of this month:
select convert(datetime, convert(varchar(8), getdate(), 120) + '01', 120)


select * from yourtable
 where DATEA <=  convert(datetime, convert(varchar(8), getdate(), 120) + '01', 120)
   and DATEA > dateadd(month, -1,  convert(datetime, convert(varchar(8), getdate(), 120) + '01', 120))

see also:

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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