Vbscript 使用Datediff查找范围值

Vbscript 使用Datediff查找范围值,vbscript,asp-classic,datediff,Vbscript,Asp Classic,Datediff,如何在VBScript中编写以下条件 >= 0 [Red] Ex.: {0,1,2,3,4...} Between -1 and -7 [Yellow] Ex.: {-1,-2,-3,-4,-5,-6,-7} ONLY Greater or equal than -8 [Green] Ex.: {-8,-9,-10,-11...} 我有以下代码,Mydate是一个有效的日期,红色部分是OK。问题是黄色,我不知道我是否能像我一样给你一个范围。它看起来被忽略了,反而变黄了一个更大的范围 &l

如何在VBScript中编写以下条件

>= 0 [Red] Ex.: {0,1,2,3,4...}
Between -1 and -7 [Yellow] Ex.: {-1,-2,-3,-4,-5,-6,-7} ONLY
Greater or equal than -8 [Green] Ex.: {-8,-9,-10,-11...}
我有以下代码,Mydate是一个有效的日期,红色部分是OK。问题是黄色,我不知道我是否能像我一样给你一个范围。它看起来被忽略了,反而变黄了一个更大的范围

<%
    IF DateDiff("d", MyDate, Now()) >= 0 THEN
%>
[Red]
<%
    ELSEIF DateDiff("d", MyDate, Now()) =< -1 OR DateDiff("d", MyDate, Now()) >= -8 THEN
%>
[Yellow]
<%
    ELSE
%>
[Green]
<%
    END IF
%>
=0那么
%>
[红色]
=-8那么
%>
[黄色]
[绿色]

当IFs变得复杂时,使用Select Case可能会使事情变得更简单

用于“短”范围;也可以处理“异常”:

Select Case DateDiff("d", dtA, dtB) ' computed just once automagically
  Case 1, 2, 3, 5  ' effectively OR without the noise => risk of messing up a complicated IF/ELSE/ELSEIF sequence
    ...
  Case 4, 6, 7, 1256
    ...
  Case Else
    ...
End Select
Dim nDiff : nDiff = DateDiff("d", dtA, dtB) ' computed just once
Select Case True ' <-- dirty? trick
  Case nDiff < -15
    ...
  Case nDiff < 0
    ...
  Case nDiff = 0
    ...
  Case nDiff < 11
    ...
  Case Else ' 11 or greater
End Select
对于“大”连续范围:

Select Case DateDiff("d", dtA, dtB) ' computed just once automagically
  Case 1, 2, 3, 5  ' effectively OR without the noise => risk of messing up a complicated IF/ELSE/ELSEIF sequence
    ...
  Case 4, 6, 7, 1256
    ...
  Case Else
    ...
End Select
Dim nDiff : nDiff = DateDiff("d", dtA, dtB) ' computed just once
Select Case True ' <-- dirty? trick
  Case nDiff < -15
    ...
  Case nDiff < 0
    ...
  Case nDiff = 0
    ...
  Case nDiff < 11
    ...
  Case Else ' 11 or greater
End Select

当IFs变得复杂时,使用Select Case可能会使事情变得更简单

用于“短”范围;也可以处理“异常”:

Select Case DateDiff("d", dtA, dtB) ' computed just once automagically
  Case 1, 2, 3, 5  ' effectively OR without the noise => risk of messing up a complicated IF/ELSE/ELSEIF sequence
    ...
  Case 4, 6, 7, 1256
    ...
  Case Else
    ...
End Select
Dim nDiff : nDiff = DateDiff("d", dtA, dtB) ' computed just once
Select Case True ' <-- dirty? trick
  Case nDiff < -15
    ...
  Case nDiff < 0
    ...
  Case nDiff = 0
    ...
  Case nDiff < 11
    ...
  Case Else ' 11 or greater
End Select
对于“大”连续范围:

Select Case DateDiff("d", dtA, dtB) ' computed just once automagically
  Case 1, 2, 3, 5  ' effectively OR without the noise => risk of messing up a complicated IF/ELSE/ELSEIF sequence
    ...
  Case 4, 6, 7, 1256
    ...
  Case Else
    ...
End Select
Dim nDiff : nDiff = DateDiff("d", dtA, dtB) ' computed just once
Select Case True ' <-- dirty? trick
  Case nDiff < -15
    ...
  Case nDiff < 0
    ...
  Case nDiff = 0
    ...
  Case nDiff < 11
    ...
  Case Else ' 11 or greater
End Select