VBA/Excel/Access/Word/Date Functions/Hour

Материал из VB Эксперт
Версия от 15:48, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Hour(time) returns Variant/Integer between 0 and 23, inclusive, representing the hour for time

   <source lang="vb">

Sub dateDemo6()

  Debug.Print Hour(Date)

End Sub

</source>
   
  


use Hour to get the hour value from a date

   <source lang="vb">

Private Sub myTime0()

   Dim time As Date
   Dim theHour As Integer
   Dim theDayOfTheWeek As Integer
   time = Now
   theHour = Hour(time)
   theDayOfTheWeek = Weekday(time)
   If (theHour > 8) And (theHour < 17) Then
       If (theDayOfTheWeek > 0) And (theDayOfTheWeek < 6) Then
           MsgBox ("You should be at work!")
       Else
           MsgBox ("I love weekends")
       End If
   Else
       MsgBox ("You should not be at work!")
   End If

End Sub

</source>