VBA/Excel/Access/Word/Data Type/Time
Displaying the current date and time in a cell
<source lang="vb">
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
</source>
Time returns A Variant/Date containing the current time according to your computer
<source lang="vb">
Sub dateDemo12()
Debug.Print time
End Sub
</source>
To assign both a date and a time you use this format:
<source lang="vb">
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
</source>