Display Today's Date & Time in VBA
Function used to displaz the current date / time is Vba.Now() This function will return the date & time in this default format: 7/14/2029 11:34:31 AM The returned output can be formatted into any desired format as given in the below code snippet.Sub get_current_date_time()
'Code from Officetricks
Dim iDate As Date
'Get Current Date & Time
iDate = VBA.Now
'Display Output
MsgBox "Unformatted: " & iDate
MsgBox "Formatted: " & VBA.Format(iDate, "dd-mmm-yyyy")
End Sub
If not a macro, a simple formula can also fetch this date value.
Excel Formula to get Date & Time
Use on of thes formula:- =Today()
- =Now()