Excel / VBA Date Function with 7 Formatting Examples

VBA Date function returns the current date of the system. It can be used with the format function to get the date in the desired format. We will show this in examples.

Date function in VBA

  • VBA Date function returns the current date of the system.
  • This is a variant type.
  • It can be used with the format function to get the date in the desired format. We will show this in examples.

An example of using Date function

We will simply display the Date in the message box to get the current date:

Output:

VBA-Date-current

You can see, it displays the current date of the system – in the set format.

Format date in day, full month name, and two digit year format

Using Date() alone might not be as meaningful as you might want to display in your Excel sheet.

Now let us have a look at formatting date by using the Date function with Format().

So first, we will show you using a Date type variable and assigning it the Date() function and using it in Format() function.

Code:

Result:

Date-DD-mmmmm-yy

In order to get the date with the full month name, use ‘m’ four times.

With full year like 2021, 2022 etc.

Just adding two more ‘yy’ to the above example and it will get us a year in four digits.

Result:

Date-DD-mmmmm-yyyy

Date in yyyymmdd format

Result

Date-yyyymmdd-format

Day, Short Month name with four digit year example

Result:

Date-short-month

Short Day name, Short Month, and Full year

Use ‘ddd’ for the short day name as follows:

Date-short-day-name

Full Day, Short Mon and four-digit year formatting

By using Date() function with Format() function, we will display the date in Full day name, short month, and four digit year:

Date-full-day-name