就是 判断一个时间是否在指定的范围里

解决方案 »

  1.   

    if d=>d1 and d<=d2 then msgbox d & "在 " & d1 & ","& d2 &" 范围内。"
    (d,d1,d2都要是日期型,如不是可用 cdate 转一下)sql server 指令中,可用 between
    如 select * from aa where datefield between '"&d1&"' and '"&d2&"'"
      

  2.   

    在哪里判断?是在语句中吗?
    between  and
      

  3.   

    你可以把小时单独取出来,例如用split ,lift等。然后把取出业的HH用cint和23,7比。
      

  4.   

    to  fxy_2002(阿勇)
    我是为了判断一个时间是否在指定的范围里!!不是单纯的判断大小方法很多.
    我要简单的方法
      

  5.   

    你试一下DateDiff。Fdate '第一个日期
    Bdate '第二个
    MIDdate '需要判断的时间if datediff("s"  Fdate,MIDdate)>0 and datediff("s"  MIDdate,Fdate)>0 then
       msgbox "在这个范围"
    end if
      

  6.   

    Private Sub Command1_Click()
    MsgBox isbetween(#9:00:00 AM#, #8:00:00 AM#, #1:00:00 PM#)
    MsgBox isbetween(#7:00:00 PM#, #6:00:00 AM#, #1:00:00 PM#)
    End Sub
    Function isbetween(ByVal time1 As Date, ByVal time2 As Date, ByVal mytime As Date) As Boolean
    isbetween = (time1 < time2 And (time1 <= mytime And time2 >= mytime)) Or ((time1 > time2 And (time1 <= mytime) Or time2 >= mytime))
    End Function
      

  7.   

    northwolves(狼行天下) 
    3个参数是什么意思?
      

  8.   

    northwolves(狼行天下)
    好象不对哦
      

  9.   

    t = "8:00:00"
        t1 = "7:00:00"
        t2 = "23:59:00"
        
        If CDate(Date & " " & t) >= CDate(Date & " " & t1) And CDate(Date & " " & t) <= CDate(Date & " " & t2) Then
            MsgBox "in"
        Else
            MsgBox "not in"
        End If
      

  10.   

    northwolves(狼行天下) 
    3个参数是什么意思?
    ---------------------------------------------
    Function isbetween(ByVal time1 As Date, ByVal time2 As Date, ByVal mytime As Date) As Boolean
    isbetween = (time1 < time2 And (time1 <= mytime And time2 >= mytime)) Or ((time1 > time2 And (time1 <= mytime) Or time2 >= mytime))
    End Function上面代码判断 mytime 是否介于time1 和 time2之间,是返回true
      

  11.   

    不带日期,那没有什么比较如果带日期,字符串比较就OK了啊"2004-07-21 00:00:00" 这个字符串肯定比"2004-07-20 23:59:59"大比较之前Format一下