Forums

ASP

This topic is locked

Listing results that are between 2 dates

Posted 21 Sep 2005 10:38:47
1
has voted
21 Sep 2005 10:38:47 Andrew Robinson posted:
hi,

having troubles...

this is what i have in my recordset:

-------------------------------------------
SQL:

SELECT *
FROM CommunityEvents
WHERE Date BETWEEN date AND date+10
ORDER BY Date
-------------------------------------------

- Now this brings up the dates from the 'CommunityEvents' table in the database.

BUT! It doesn't bring up the the dates from today upto the next 10 days.

As you can see i have them set as variables (date and date+10)

This is the code for those variables:

--------------------------
Dim date1, date2
date1 = date
date2 = date+10
%>
-------------------------

- now, the variables above dont do much. What i would like them to look like is this:

---------------------
Dim date1, date2
date1 =<%=date%>
date2 =<%=date+10%>
---------------------

- Now these variables should call todays date (&lt;%=date%&gt<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle> and the date 10 days from now (&lt;%=date+10%&gt<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>. BUT! they dont, it doesnt work at all.

If these variables did work then i could just call the variables that are shown in the SQL statement at the top.

Now, i would love to know how you do this becuase i would be really really happy and mainly because i've been trying to work it out all day and its getting a bit frustrating.

thankyou

Replies

Replied 23 Sep 2005 21:18:07
23 Sep 2005 21:18:07 Jason Labbe replied:
Try this:

Dim date1
Dim date2
date1 = getdate()
date2 = getdate() + 10


Then in your select statement:

SELECT *
FROM CommunityEvents
WHERE Date BETWEEN date1 and date2
ORDER BY Date

I hope this helps!

J
Replied 23 Sep 2005 21:21:03
23 Sep 2005 21:21:03 Jason Labbe replied:
You could also change your select statement to:

SELECT *
FROM CommunityEvents
WHERE Date &gt;= date1 and &lt;= date2

This will include any events on todays date and on the date 10 days from now. If you do BETWEEN, it excludes todays date and the date 10 days from now, just gives you everything Greater then Date1 and Less then Date2

J

Reply to this topic