How to create a query from current date to and a year ago?

General discussion about calendars and calendar software.
kokilasoral
Posts: 1
Joined: Mon May 30, 2016 2:52 am

How to create a query from current date to and a year ago?

Post by kokilasoral » Thu Jun 02, 2016 2:23 am

I want a query where I need to take all results where the date is between current and a year ago. So if the query is track tomorrow, the results are successful to be a little bit unlike than they were if it was run today. If I run this today, it would essentially be like saying "where the date is between 6/1/2014 and 6/6/2016." Tomorrow, between 6/2/2014 and 6/7/2016, and so on.
I could setup it just the similar as a regular WHERE clause concerning dates. Code is
WHERE CreateDate BETWEEN (DATEADDS(Year,-1,GETDATE()) AND (GetDATE())
First, I'm not sure if the DATEADDS() part is what I should use -- I just tried it depends on what I was read on another forum. I've got a red wavy telling me I've got a syntax fault near AND.
Can anyone solve my issue?

User avatar
VueSoft
Dan Chartrand
Posts: 3851
Joined: Sat Aug 23, 2008 12:39 am
Location: St. Louis, Missouri, USA
Contact:

Re: How to create a query from current date to and a year ag

Post by VueSoft » Thu Jun 02, 2016 11:10 pm

Hi kokilasoral, welcome to the forums. Is your question related to VueMinder, or SQL syntax in general? VueMinder doesn't provide an interface for direct SQL queries.

Also, SQL syntax can vary depending on the database system you're using. Here's my best guess...

Code: Select all

SELECT * FROM MyTable WHERE CreateDate BETWEEN CURDATE() - INTERVAL 1 YEAR AND CURDATE()
Dan Chartrand, Founder
VueSoft LLC | St. Louis, Missouri, USA

MarryJain
Posts: 1
Joined: Sat Jun 04, 2016 7:49 am

Re: How to create a query from current date to and a year ag

Post by MarryJain » Sat Jun 04, 2016 8:14 am

Try the below option, it may help you to find the answer.
CONCAT(<enter date i.e. yyyymm>, '01') AS Date_SK

Answer resource: a training on the concepts of SQL from a well experienced trainer from intellipaat made me to find answers to the particular question.

Post Reply