...

View Full Version : How to get all dates between two dates?



mattboy_slim
01-03-2007, 09:55 PM
I have a database where there is a "Start Date" and and "End Date" of an event.
I need to get all the days between those two days.

The reason I need this is because of a calendaring application where I'm highlighting days where events occur.

Here is my current code, which highlights both the start date and the end date, but I also need the days between those days highlighted.



oCalendar.AddHightlight(rs_events.Fields.Item("f_datestart").Value)
oCalendar.AddHightlight(rs_events.Fields.Item("f_dateend").Value)


I need something like this, but I'm not sure how to accomplish the coding. I'm assuming that if done correctly, you could do away with the individual start and end dates, and simply get all dates with one string, but again, I may be wrong.


oCalendar.AddHightlight(rs_events.Fields.Item("f_datestart").Value)
oCalendar.AddHightlight((rs_events.Fields.Item("f_datestart").Value) - (rs_events.Fields.Item("f_dateend").Value))
oCalendar.AddHightlight(rs_events.Fields.Item("f_dateend").Value)

Spudhead
01-04-2007, 12:34 PM
Surely you just need to stick a loop in there?

Like:


<%
dim dStartDate, dCurrentDate, dEndDate
dStartDate = cDate(rs_events.Fields.Item("f_datestart").Value)
dCurrentDate = dStartDate
dEndDate = cDate(rs_events.Fields.Item("f_dateend").Value)

oCalendar.AddHightlight(dStartDate)
do while dCurrentDate < dEndDate
dCurrentDate = dateAdd("D",1,dCurrentDate)
oCalendar.AddHightlight(dCurrentDate)
loop
oCalendar.AddHightlight(dEndDate)
%>

I'm assuming your oCalendar.AddHightlight() function takes a date variable but that should work in theory, right?

mattboy_slim
01-04-2007, 06:02 PM
TOTALLY kickass!
Thanks Spudhead, that works perfectly.
Here is your code in action:
http://portal.thinix.com/events.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum