How to Format Date in Excel via VBA

In this tutorial, we will teach you how in Excel, the format date feature can be applied using Visual Basic. Basically, there are many vba excel format date keywords that can be used in your code to display the date in the format you want.

Step 1 – Formatting Date in Excel

Over here, we have written a basic code which will show you the time stamp when the record was updated.

The only thing left here is the format of the date which is to be displayed. For this tutorial, we will show you four different ways in which you can format the date.

In excel, to format date, you can use the Format keyword after which we have typed in the expression, which in this case is Date. After that comes the format of the expression, which we have kept as “General Date”.

General Date format for the date

Step 2 – General Date Format

Now let’s see how the output looks like. When we update the first record over here, you can see that the time stamp field is automatically updated. In Excel, The General Date format basically displays the date according to the system settings.

displaying system date

Step 3 – Long Date Format

Moving back to the format section of the code, let’s replace General Date with “Long date”.

Now when we update the record, you can see that the format of the date is different this time. The day and the month are appearing in words, rather than numbers.

changing format to long date

Step 4 – Medium Date Format

Moving forward, the Medium Date attribute displays the date with dashes in the middle instead of slashes.

changing format to medium date

Step 5 – Custom Date Format

And lastly, you can manually define how the date should be formatted. For example, over here, we want the day to come first, then the month and then the year. So replace the format parameter value with ‘dd/mm/yyyy’.

When youe update the record, you would see that the date is displayed accordingly.

So these are the different vba excel format date keywords that can be used in Excel.

changing to custom date format