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&"'"
在哪里判断?是在语句中吗? between and
你可以把小时单独取出来,例如用split ,lift等。然后把取出业的HH用cint和23,7比。
to fxy_2002(阿勇) 我是为了判断一个时间是否在指定的范围里!!不是单纯的判断大小方法很多. 我要简单的方法
你试一下DateDiff。Fdate '第一个日期 Bdate '第二个 MIDdate '需要判断的时间if datediff("s" Fdate,MIDdate)>0 and datediff("s" MIDdate,Fdate)>0 then msgbox "在这个范围" end if
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
northwolves(狼行天下) 3个参数是什么意思?
northwolves(狼行天下) 好象不对哦
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
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
(d,d1,d2都要是日期型,如不是可用 cdate 转一下)sql server 指令中,可用 between
如 select * from aa where datefield between '"&d1&"' and '"&d2&"'"
between and
我是为了判断一个时间是否在指定的范围里!!不是单纯的判断大小方法很多.
我要简单的方法
Bdate '第二个
MIDdate '需要判断的时间if datediff("s" Fdate,MIDdate)>0 and datediff("s" MIDdate,Fdate)>0 then
msgbox "在这个范围"
end if
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
3个参数是什么意思?
好象不对哦
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
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