Page 1 of 1

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

PostPosted: Thu Jun 02, 2016 2:23 am
by kokilasoral
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?

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

PostPosted: Thu Jun 02, 2016 11:10 pm
by VueSoft
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()

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

PostPosted: Sat Jun 04, 2016 8:14 am
by MarryJain
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.