需求:判断当前是否是工作时间
工作事件为:8:30-11:30 和 14:00-5:30
还有判断是否是周末周末的话也不算工作时间。非常感谢!

解决方案 »

  1.   

    dim datenow as datetime
    datenow = now()
    if #8:30# <= datenow and datenow <=#11:30# or _
      #14:00# <= datenow and datenow <=#17:30# then 
       msgbox "是工作时间"
    else
       msgbox "不是工作时间哦"
    endif
      

  2.   

    Private Sub Command1_Click()    If DatePart("w", Now) = vbSaturday Or DatePart("w", Now) = vbSunday Then
            MsgBox "休息日"
        End If    If (Format(Now, "hh:ss") > Format("8:30", "hh:ss")) And (Format(Now, "hh:ss") < Format("11:30", "hh:ss")) Then
            MsgBox "工作时间"
        Else
        End If
        
        If (Format(Now, "hh:ss") > Format("14:00", "hh:ss")) And (Format(Now, "hh:ss") < Format("17:30", "hh:ss")) Then
            MsgBox "工作时间"
        Else
            MsgBox "不是工作时间"
        End IfEnd Sub
      

  3.   

    If Weekday(Now) = 1 Or Weekday(Now) = 7 Then
        MsgBox "不是工作时间哦"
    ElseIf #8:30:00 AM# <= Time And Time <= #11:30:00 AM# Or # _
      2:00:00 PM# <= Time And Time <= #5:30:00 PM# Then
       MsgBox "是工作时间"
    Else
       MsgBox "不是工作时间哦"
    End If
      

  4.   

    补全
    Private Sub Command1_Click()    If DatePart("w", Now) = vbSaturday Or DatePart("w", Now) = vbSunday Then
            MsgBox "休息日"
            Exit Sub
        End If    If (Format(Now, "hh:ss") > Format("8:30", "hh:ss")) And (Format(Now, "hh:ss") < Format("11:30", "hh:ss")) Then
            MsgBox "工作时间"
        Else
            MsgBox "不是工作时间"
        End If
        
        If (Format(Now, "hh:ss") > Format("14:00", "hh:ss")) And (Format(Now, "hh:ss") < Format("17:30", "hh:ss")) Then
            MsgBox "工作时间"
        Else
            MsgBox "不是工作时间"
        End IfEnd Sub
      

  5.   

    Public Function IsWorkTime() As Boolean
    Dim t
        If Weekday(Date, vbMonday) < 6 Then
            t = Tiem
            IsWorkTime = (t >= Cdate("8:30") And t <= Cdate("11:30")) Or _
                         (t >= Cdate("14:00") And t <= Cdate("17:00")) 
        End If
    End Function