Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff in Query Expression

Status
Not open for further replies.

mrf3000

Programmer
Feb 4, 2003
15
Hi,

Here is the problem. I have a range of dates for which I need to determine whether it is between 10 and 15 days. The first date is logged in a table say it would be 11/1/03. The last date is today's date so it would be 12/5/03. date1 is the field name in the table

I have it set up as for next loop

for dtdate = rst!DateLog to date()
strwhere1 = strwhere1 & &quot; OR (datediff('d', date1,&quot; & dtdate & &quot;)>=10 and datediff('d',date1,&quot; & dtdate & &quot;<15))&quot;
next dtdate

now this strwhere1 statement is inserted into the rest of a sql statment however, when I debug the sql statement it takes the date1 as a literal instead of as a field name. This might be really something simple which I have overlooked but any help would be appreciated. I tried using brackets, back quotes, etc...but nothing seems to work.

Thanks,
Marc

 
You are comparing the DAY. What happens when DAY1 is GREATER than DAY2, assuming that DATE1 is LESS THAN Date2???

You need to be comapring DATES!

DATE2 - DATE1 yields the difference in DAYS assuming that your DATES are indeed DATES and NOT JUST date string reprsentations!

:)

Skip,
 
You usually need &quot;#&quot; around dates (other than fields) as in

strwhere1 = strwhere1 & _
&quot; OR (datediff('d', date1, #&quot; & dtdate & &quot;#)>=10 and datediff('d',date1,#&quot; & dtdate & &quot;#<15))&quot;
 
Golom,

Thanks.....I figured that one out myself after about two hours. It was just a stupid mistake.

Thanks again,
mrf3000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top