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/2019# returns 4/1/2019.

Dim dtFirstDayInQuarter As Date
Dim dt As Date: dt = #6/23/2019#
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/2019# returns 6/30/2019.

Dim dtLastDayInQuarter As Date
Dim dt As Date: dt = #6/23/2019#
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/2019# returns 4.

Dim dtFirstMonthInQuarter As Integer
Dim dt As Date: dt = #6/23/2019#
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/2019# returns 6.

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