Lieutenant Dan
Lieutenant Dan

Reputation: 8294

Between 2 dates, & detecting todays date (if in between range)

Trying another attempt at this question:

With the below code, I'm trying to articulate a date range; May 10 - June 8th. I'm outputting a unique thumbnail image per date in this range (coming together as a stylized calendar of sorts); I need to also detect, within this range, today's date. As a .today style class will be appending for today's date. I achieved this previously when the date range was just within one month, 1 - 31 (and that code is under the most recent attempt / which is original code) this same code could not work because now it's not as simple as 1 - 31 and declaring the month name statically, now it's two months and 10 - 31 and then 1 - 8. Also, not my most recent attempt fails so hard the page doesn't even compile and is just white.

<%
Dim d1 As New Date(2015, 5, 10)
Dim d2 As New Date(2015, 6, 8)

Dim DaysBetween As Long = DateDiff(DateInterval.Day, d1, d2)

Dim d3 As Date

For d As Long = 0 To DaysBetween
    d3 = d1.AddDays(d)
    If d3 < Today() Then
    time = "past"
    ElseIf d3 = Today Then
    time = "today"
    Else
    time = "future"
    End If

    Dim suffix As String = Suffixer(d3.Day)

    response.write("<section id='day_"& i &"' class='calSquare  " & time &"'><article class='dateImage' style='background-image: url(images/Calendar_Thumbnails/Day_"&i&".jpg)'></article></article><article class='dateTitle'> "&i&suffix&"</article></section>")

    Next
    <!--response.write(products(0))-->
%>

Original functional code; articulating one month.

<%
        For i = 1 to 31
        dim time
        If i < day_part Then
        time = "past"
        ElseIf i = day_part Then
        time = "today"
        Else
        time = "future"
        End If

        suffix = Suffixer(i)

        response.write("<section id='day_"& i &"' class='calSquare  " & time &"'><article class='dateImage' style='background-image: url(images/Calendar_Thumbnails/Day_"&i&".jpg)'></article></article><article class='dateTitle'>May "&i&suffix&"</article></section>")

        Next
        <!--response.write(products(0))-->
    %>

Upvotes: 0

Views: 72

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200523

Your first code sample isn't valid VBScript. The language doesn't support constructs like Dim var As type = value, so that's probably why the page isn't displayed.

As for listing the dates within a range while highlighting the current date, you could do something like this:

today = Date

firstDay = DateValue("2015-05-10")
lastDay  = DateValue("2015-06-08")

d = firstDay
While d <= lastDay
  If d = today Then
    response.write "today"
  Else
    response.write "other day in range"
  End If
  d = d + 1
Wend

Upvotes: 2

Related Questions