Displaying the current date and time in a cell : Time « Data Type « VBA / Excel / Access / Word






Displaying the current date and time in a cell

 
Sub DateAndTime()
    TheDate = Format(Date, "Long Date")
    TheTime = Format(time, "Medium Time")
    Select Case time
        Case Is < 0.5:     Greeting = "Good Morning, "
        Case Is >= 0.7083: Greeting = "Good Evening, "
        Case Else:         Greeting = "Good Afternoon, "
    End Select

    MsgBox TheDate & vbCrLf & TheTime, vbOKOnly, Greeting
End Sub

 








Related examples in the same category

1.Time returns A Variant/Date containing the current time according to your computer
2.To assign both a date and a time you use this format: