Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    NW Iowa
    Posts
    185
    Thanks
    9
    Thanked 0 Times in 0 Posts

    How to get all dates between two dates?

    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.

    Code:
      	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.
    Code:
      	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)

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Surely you just need to stick a loop in there?

    Like:

    Code:
    <%
    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?
    Last edited by Spudhead; 01-04-2007 at 01:23 PM.

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    NW Iowa
    Posts
    185
    Thanks
    9
    Thanked 0 Times in 0 Posts
    TOTALLY kickass!
    Thanks Spudhead, that works perfectly.
    Here is your code in action:
    http://portal.thinix.com/events.asp


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •