Search
Close this search box.

VBA – Now


The Now() function in VBA returns the current system date and time.

It is a versatile and essential tool for working with dates and times in VBA. It provides a simple and efficient way to obtain the current system date and time, enabling you to incorporate real-time information into your applications.

Syntax:

Now()

Example

				
					Sub GetCurrentDateTime()
  Dim currentDateTime As Date
  currentDateTime = Now()
  MsgBox "Current Date and Time: " & currentDateTime 
End Sub
				
			

Use Cases:

  • Timestamping Events: Recording the exact date and time of an event or action.
  • Creating Logs: Generating logs with timestamps for auditing or debugging purposes.
  • Scheduling and Reminders: Creating time-based reminders or scheduling tasks.
  • Data Entry and Validation: Ensuring that date and time data is accurate and up-to-date.