两个月之间的日期范围并检测今天的日期(今天的新样式)
date range between two months and detect todays date (new styles on today)
更新: 最终目标:
显示 5 月 10 日至 6 月 8 日,所有日期都带有前缀 May 或 June(月份名称)。今天是哪个日期.. 类似于那个日历日周围的边框(风格的东西)所以输出之间的所有日期,每天突出显示今天的 'date' 。 像日历一样的输出,每个日历日(在描述的日期范围之间)有各种(独特的图像)。将特定样式添加到 'today' 的日历日。因此,如果是 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))-->
%>
*我已将 i 替换为 d 全面(通过上述尝试)——但没有用!我也用最新的代码更新了我的问题。我得到的反馈是逻辑是正确的,但可能不是使用构造的有效 VBscript。任何其他建议都会很棒!*
规则 #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
fnostro 的
Rule #27: don't use Integers when you mean Dates
是正确的,但答案违反了
Rule #1: use 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
' !!
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>
更新: 最终目标:
显示 5 月 10 日至 6 月 8 日,所有日期都带有前缀 May 或 June(月份名称)。今天是哪个日期.. 类似于那个日历日周围的边框(风格的东西)所以输出之间的所有日期,每天突出显示今天的 'date' 。 像日历一样的输出,每个日历日(在描述的日期范围之间)有各种(独特的图像)。将特定样式添加到 'today' 的日历日。因此,如果是 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))-->
%>
*我已将 i 替换为 d 全面(通过上述尝试)——但没有用!我也用最新的代码更新了我的问题。我得到的反馈是逻辑是正确的,但可能不是使用构造的有效 VBscript。任何其他建议都会很棒!*
规则 #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
fnostro 的
Rule #27: don't use Integers when you mean Dates
是正确的,但答案违反了
Rule #1: use 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
' !!
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>