Getting the Current Date and Time

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Three functions in Microsoft® Visual Basic® for Applications (VBA) can tell you exactly when it is: the Now, Date, and Time functions. The Now function returns both the date and time portions of a Date variable. For example, calling the Now function from the Immediate window returns a value such as this one:

2/23/98 6:16:47 PM

The Date function returns the current date. You can use it if you do not have to know the time. The Time function returns the current time, without the date.

See Also

Working with Dates and Times | The Date Data Type | Formatting a Date | Date Delimiters | Assembling a Date | Getting Part of a Date | Adding and Subtracting Dates | Calculating Elapsed Time