VBA/Excel/Access/Word/Data Type/Time
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
Time returns A Variant/Date containing the current time according to your computer
Sub dateDemo12()
Debug.Print time
End Sub
To assign both a date and a time you use this format:
Sub main()
Dim datTime As Date
datTime = #6/30/1998 3:20:15 AM#
End Sub
Sub dateDemo()
Dim datPayBy As Date
datPayBy = Date + 60
Debug.Print "Payment is due by " & datPayBy
End Sub