Zoho Deluge - Determine Quarter from Date with Fiscal Year

What?
This is a quick article on what should be a simple mathematics equation: Determine the quarter from a given month.

Why?
Fine if you are determining the quarter by the month and your Fiscal year starts from January, simply divide by 3...

How?
I'm showing this in Zoho Deluge but the logic can be adapted to other code. You will need this snippet of code for the examples below:
l_Months = {1,2,3,4,5,6,7,8,9,10,11,12};
l_MonthNames = {"January","February","March","April","May","June","July","August","September","October","November","December"};

Here's the standard code you'd expect if your Fiscal year starts in January (Divide by 3 and round up):
for each v_Month in l_Months
{
	v_Quarter = (v_Month.toLong() / 3).ceil();
	info "Month: " + l_MonthNames.get(v_Month-1) + " :: Quarter: " + v_Quarter;
}
Yields:
Month: January :: Quarter: 1
Month: February :: Quarter: 1
Month: March :: Quarter: 1
Month: April :: Quarter: 2
Month: May :: Quarter: 2
Month: June :: Quarter: 2
Month: July :: Quarter: 3
Month: August :: Quarter: 3
Month: September :: Quarter: 3
Month: October :: Quarter: 4
Month: November :: Quarter: 4
Month: December :: Quarter: 4

Now what if your year starts in August? You can do this:
// let's say financial year starts in August
v_MonthStart = 8;
for each v_Month in l_Months
{
	v_Quarter = 1 + (((v_Month - v_MonthStart) % 12) / 3).floor();
	if(v_Quarter < 1)
	{
		v_Quarter = v_Quarter + 4;
	}
	info "Month: " + l_MonthNames.get(v_Month-1) + " :: Quarter: " + v_Quarter;
}
Yields:
Month: January :: Quarter: 2
Month: February :: Quarter: 3
Month: March :: Quarter: 3
Month: April :: Quarter: 3
Month: May :: Quarter: 4
Month: June :: Quarter: 4
Month: July :: Quarter: 4
Month: August :: Quarter: 1
Month: September :: Quarter: 1
Month: October :: Quarter: 1
Month: November :: Quarter: 2
Month: December :: Quarter: 2

And just to prove the same code snippet works for any month, let's use the same code but start in April:
// let's say financial year starts in April
v_MonthStart = 4;
for each v_Month in l_Months
{
	v_Quarter = 1 + (((v_Month - v_MonthStart) % 12) / 3).floor();
	if(v_Quarter < 1)
	{
		v_Quarter = v_Quarter + 4;
	}
	info "Month: " + l_MonthNames.get(v_Month-1) + " :: Quarter: " + v_Quarter;
}
Yields:
Month: January :: Quarter: 4
Month: February :: Quarter: 4
Month: March :: Quarter: 4
Month: April :: Quarter: 1
Month: May :: Quarter: 1
Month: June :: Quarter: 1
Month: July :: Quarter: 2
Month: August :: Quarter: 2
Month: September :: Quarter: 2
Month: October :: Quarter: 3
Month: November :: Quarter: 3
Month: December :: Quarter: 3

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.