Sql date calculation

Hello,

When the qry below is fired i basically want it to display data 2 weeks before the current date. So I need some form of calculation similar to the following:



sSql1 = "select * from qryclosed where [date closed] = todays date - 14 days

so if i launched the qry today it should pull all data from the field 'closed date' starting from 2/11/04 through to 15/11/04.

I hope this makes sense.

Thanks in advance

jono1970Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ShauliCommented:
'For Access DB
sSql1 = "select * from qryclosed where [date closed] = #" & Date - 14 & "#;"

If you are using sql server then replace the # with a single quote (')

S
0
Saqib KhanSenior DeveloperCommented:
OR

sSql1 = "select * from qryclosed where [date closed] = #" & DateAdd("d", -14, Date()) & "#;"
0
jono1970Author Commented:
Hi,

Slight problem with code. it only displays data with a date of 2/11/2004.

in the example it shuld have displayed data from 2/11/2004 through to current date.

I have tried using the between command but to no avail.

thanks
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ajgilbertCommented:
Jono,

Presuming you are querying an Access database, the following will work...

sSql1 = "select * from qryclosed where [closed date] between (date() - 14) and date()"


0
kishore3576Commented:
Just change your query to

sSql1 = "select * from qryclosed where [date closed] between #" & DateAdd("d", -14, Date()) & "# and #" & date() & "#
0
kishore3576Commented:
Add a double quote at the end also.
0
jono1970Author Commented:
Hi,

Still not working :O)

This is the error message:

No value given for one or more required parameters.

I am using VB6 and Access

Thanks
0
kishore3576Commented:
Here is one of the query that I am using

"select * into tbldate from af where date between #" & Format(DateAdd("d", -14, Date), "mm/dd/yyyy") & "# and #" & Format(Date, "mm/dd/yyyy") & "#"

Hope this helps u
0
kishore3576Commented:
using this your query will become

sql = "select * from qryclosed where [date closed] between #" & format(dateadd("d",-14,date), "mm/dd/yyyy") & "# and #" & format(date, "mm/dd/yyyy") & "#"
0
ajgilbertCommented:
Jono,

The example I put above works with VB6 and Access. Do you get that error message with my example ?



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jono1970Author Commented:
Hi,

Your solution displayed the same error. I will close this ticket now as you have nearly solved my problem and I have learned something to say the least.

Thanks for your assistance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.