VBA/Excel/Access/Word/Date Functions/Now

Материал из VB Эксперт
Перейти к: навигация, поиск

Date and Now

Sub dateFunctions()
   Debug.Print "The present date and time is: " & Now
   Debug.Print "Today"s date is: " & Date
End Sub

Now returns a Variant/Date containing the current date and time according to your computer

Sub dateDemo10()
   Debug.Print Now
End Sub

Use Now to retrieve current Date and Time

Private Sub myTime()
    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!")
            MsgBox ("I love weekends")
        End If
        MsgBox ("You should not be at work!")
    End If
End Sub