如果我想判断在11:30之前为早餐,11:30-16:00为午餐,16:00之后为晚餐,如何写?
如if date>11:30 then
  a="早餐”
 endif

解决方案 »

  1.   

    select case now()
      case is <#11:30#
        msgbox "breakfast"
      case is <#16:00
        msgbox "lunch"
      case else
        msgbox "supper"
    end select
      

  2.   

    我用的是SQL数据库
    时间是调用的服务器的时间,按照你的意思这样写就可以了。
    dim a as date
    dim s as date
    a=Format(servertime, "yyyy.mm.dd --- hh:mm:ss")
    s=Format(Date, "hh:mm:ss")
    这样就可以得出具体的时间值了。
    if s > "11:30" then  就可以了。但是如果用DATE直接取本机的时间不行,因为DATE不包括几点几分。
      

  3.   

    Option ExplicitPrivate Sub Command1_Click()
        
        Dim ls          As String    ls = Format$(Now(), "HHMM")
        
        If ls < "1130" Then
            MsgBox "11:30之前为早餐"
        ElseIf ls >= "1130" And ls <= "1600" Then
            MsgBox "11:30-16:00为午餐"
        ElseIf ls > "1600" Then
            MsgBox "16:00之后为晚餐"
        End If
        
    End Sub
      

  4.   

    象楼上的同志说的用NOW也能实现,而且方便。
    dim s as date
    s=format(now,"hh:mm")
    if s > "11:30" then  就可以了。
      

  5.   

    象楼上的同志说的用NOW也能实现,而且方便。
    dim s as date
    s=format(now,"hh:mm")
    if s > "11:30" then  就可以了。