Quarter date functions VBA

This page displays code fragments for the following Quarter related calculations:

First day in quarter

Given a certain date, what is the first day (date) in it's quarter. For example dt = #6/23/2022# returns 4/1/2022.


Dim dtFirstDayInQuarter As Date
Dim dt As Date: dt = #6/23/2022#
dtFirstDayInQuarter = DateSerial(Year(dt), Int((Month(dt) - 1) / 3) * 3 + 1, 1)

Last day in quarter

Given a certain date, what is the last day (date) in it's quarter. For example dt = #6/23/2022# returns 6/30/2022.


Dim dtLastDayInQuarter As Date
Dim dt As Date: dt = #6/23/2022#
dtLastDayInQuarter = DateSerial(Year(dt), Int((Month(dt) - 1) / 3) * 3 + 4, 0)

First month in quarter

Given a certain date, what is the first month (number) in it's quarter. For example dt = #6/23/2022# returns 4.


Dim dtFirstMonthInQuarter As Integer
Dim dt As Date: dt = #6/23/2022#
dtFirstMonthInQuarter = Int((Month(dt) - 1) / 3) * 3 + 1

Last month in quarter

Given a certain date, what is the last month (number) in it's quarter. For example dt = #6/23/2022# returns 6.


Dim iLastMonthInQuarter As Integer
Dim dt As Date: dt = #6/23/2022#
iLastMonthInQuarter = Int((Month(dt) - 1) / 3) * 3 + 3

Below image shows the Code VBA add-in support for VBA Date procedures.

support for VBA Date procedures