Date and time functions in Excel VBA

Description of date and time functions.

The VBA date functions as per the name indicate are used to manipulate values ​​related to dates and time. On their basis, we can receive any parameter from the given date, such as day, month, year, etc. We can also subtract two dates from each other. If we want to enter the value of date, time or date and time value into our VBA code, we can use the following code:

List of date and time functions in VBA

I place the functions of the VBA date in the table. First of all, we will know the functions indicating the current date. Whole below:


As you can see, some of our functions use time intervals as arguments. These are Intervals for the  DATADD (),  DATEDIFF (),  DATEPART () functions. Below is a table showing each of the intervals. It is these values ​​that we enter as a function argument.

Interval Importance
yyyy Year
q Quarter
m Month
s Day of the year
d Day
in Day of the week
abovementioned Week
h Hour
n Minute
s Second

An example using the date and time function.

A brief example below. We want to check how the functions we have just learned work. Create a program in the new module. Let’s add 3 VBA variables to the code with date, time and date and time values ​​simultaneously.

I put the Excel file with our example below:


Tasks (You can enter the solution in a comment)

  1. Calculate on the basis of today’s date day, month, year, quarter.
  2. Based on the current time, insert the hour, minutes and seconds into the cells of the worksheet
  3. Check how many days have remained until the end of the year.
  4. Check the day of the week for your birthday.

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: