两个月之间的日期范围并检测今天的日期(今天的新款式)

时间:2015-04-27 21:37:41

标签: arrays date vbscript

更新: 结束目标:

显示5月10日 - 6月8日,所有日期均为前缀5月或6月(月份名称)。今天哪个日期...就像那个日历日的边界(样式东西)所以输出之间的所有日期,每天突出显示今天的'日期'。 输出类似日历,每个日历日具有各种(唯一图像)(在描述的日期范围之间)。将特定样式添加到“今天”的日历日。因此,如果它是第11个,那么5月11日的特定样式在该日历区域中可见 - 如果6月2日相同。

我可以在一个月/同月内完成;以下,但现在不是那么简单,因为我的日期范围在两个月之间。 5月10日 - 6月8日。我怎样才能分成两个数组 - 而且它不仅仅是一个日期范围;我需要检测今天是否是白天。

<%
    For i = 10 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'> "&i&suffix&"</article></section>")

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

最新代码通过下面的回答建议(其他人已经审核过它可能不是有效的VBscript但只是我得到的建议):

<%
    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
        ElseIf d3 = Today Then
        Else
        End If

        Dim suffix As String = Suffixer(d3.Day)

        Next

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

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

*我已全部用 d 替换 i (以上尝试) - 并且没有干嘛!我也用最新的代码更新了我的问题。我得到的反馈是逻辑是正确的,但可能不是有效的VBscript使用的结构。任何其他建议都会很棒!*

2 个答案:

答案 0 :(得分:1)

规则#27:当你的意思是日期时,不要使用整数:

在这里 - 去玩 - 我会留给你填写空白和调试:

    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
        ElseIf d3 = Today Then
        Else
        End If

        Dim suffix As String = Suffixer(d3.Day)
    Next

答案 1 :(得分:-1)

fnostro的

  

规则#27:当你的意思是日期时不要使用整数

是正确的,但答案违反了

  

规则#1:使用VBScript

因此,如果您需要回答COOOL的问题(以及VBScript中几乎所有格式问题的解决方案(参见here):

Option Explicit

' !! http://csharphelper.com/blog/2014/11/convert-an-integer-into-an-ordinal-in-c/
' Return the int's ordinal extension.
Function OrdExt(value)
    ' Start with the most common extension.
    OrdExt = "th"
    ' Examine the last 2 digits.
    Dim last_digits : last_digits = value Mod 100
    ' If the last digits are 11, 12, or 13, use th. Otherwise:
    If last_digits < 11 Or last_digits > 13 Then
        ' Check the last digit.
        Select Case last_digits Mod 10
            Case 1
                OrdExt = "st"
            Case 2
                OrdExt = "nd"
            Case 3:
                OrdExt = "rd"
        End Select
    End If
End Function

' !! https://stackoverflow.com/a/11262441/603855
Class cFormat
  Private m_oSB
  Private Sub Class_Initialize()
    Set m_oSB = CreateObject("System.Text.StringBuilder")
  End Sub ' Class_Initialize
  Public Function formatOne(sFmt, vElm)
    m_oSB.AppendFormat sFmt, vElm
    formatOne = m_oSB.ToString()
    m_oSB.Length = 0
  End Function ' formatOne
  Public Function formatArray(sFmt, aElms)
    m_oSB.AppendFormat_4 sFmt, (aElms)
    formatArray = m_oSB.ToString()
    m_oSB.Length = 0
  End Function ' formatArray
End Class ' cFormat

Dim oF     : Set oF = New cFormat
Dim sFmt   : sFmt   = "<section id='day_{0}' class='calSquare {1}'><article class='dateImage' style='background-image: url(images/Calendar_Thumbnails/{2}/Day_{0}.jpg)'></article></article><article class='dateTitle'>{2} {0}{3}</article></section>"
Dim dToday : dToday = #3/1/2012#  ' fake needed for Feb 29th demo
Dim aTime  : aTime  = Split("past today future")
Dim d
For d = #2/27/2012# To #3/4/2012#
    WScript.Echo d, TypeName(d), aTime(Sgn(DateDiff("d", dToday, d)) + 1)
    WScript.Echo oF.formatArray(sFmt, Array(Day(d), aTime(Sgn(DateDiff("d", dToday, d)) + 1), MonthName(Month(d)), OrdExt(Day(d))))
Next

输出:

cscript 29906416.vbs
27.02.2012 Date past
<section id='day_27' class='calSquare past'><article class='dateImage' style='background-image: url(images/Cal
endar_Thumbnails/February/Day_27.jpg)'></article></article><article class='dateTitle'>February 27th</article><
/section>
28.02.2012 Date past
<section id='day_28' class='calSquare past'><article class='dateImage' style='background-image: url(images/Cal
endar_Thumbnails/February/Day_28.jpg)'></article></article><article class='dateTitle'>February 28th</article><
/section>
29.02.2012 Date past
<section id='day_29' class='calSquare past'><article class='dateImage' style='background-image: url(images/Cal
endar_Thumbnails/February/Day_29.jpg)'></article></article><article class='dateTitle'>February 29th</article><
/section>
01.03.2012 Date today
<section id='day_1' class='calSquare today'><article class='dateImage' style='background-image: url(images/Cal
endar_Thumbnails/March/Day_1.jpg)'></article></article><article class='dateTitle'>March 1st</article></section
>
02.03.2012 Date future
<section id='day_2' class='calSquare future'><article class='dateImage' style='background-image: url(images/Ca
lendar_Thumbnails/March/Day_2.jpg)'></article></article><article class='dateTitle'>March 2nd</article></sectio
n>
03.03.2012 Date future
<section id='day_3' class='calSquare future'><article class='dateImage' style='background-image: url(images/Ca
lendar_Thumbnails/March/Day_3.jpg)'></article></article><article class='dateTitle'>March 3rd</article></sectio
n>
04.03.2012 Date future
<section id='day_4' class='calSquare future'><article class='dateImage' style='background-image: url(images/Ca
lendar_Thumbnails/March/Day_4.jpg)'></article></article><article class='dateTitle'>March 4th</article></sectio
n>