在 2 个日期之间,并检测今天的日期(如果在范围之间)

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

再次尝试这个问题:

使用下面的代码,我试图阐明一个日期范围; 5 月 10 日至 6 月 8 日。我在这个范围内的每个日期输出一个独特的缩略图(作为各种程式化的日历组合在一起);我还需要在此范围内检测今天的日期。作为 .today 样式,class 将附加到今天的日期。我之前在日期范围仅在一个月内 1 - 31 时实现了这一点(并且该代码是最近一次尝试/这是原始代码)同样的代码无法工作,因为现在它不像 1 - 31 那样简单并且静态声明月份名称,现在是两个月,然后是 10 - 31,然后是 1 - 8。另外,不是我最近的尝试失败了,页面甚至没有编译,只是白色的。

<%
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))-->
%>

原始功能代码;阐明一个月。

<%
        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))-->
    %>

您的第一个代码示例不是有效的 VBScript。该语言不支持像 Dim var As type = value 这样的结构,所以这可能是页面未显示的原因。

至于在突出显示当前日期的同时列出范围内的日期,您可以这样做:

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