Skip to content

Instantly share code, notes, and snippets.

@mrlynn
Last active December 2, 2020 20:57
Show Gist options
  • Save mrlynn/48ef32e6ca960b2b5796a98c8ca0daaa to your computer and use it in GitHub Desktop.
Save mrlynn/48ef32e6ca960b2b5796a98c8ca0daaa to your computer and use it in GitHub Desktop.
Get Fiscal Year from Date in Google App Script - FY begins in Feb
function fyQ(date) {
var d = new Date(date);
var month = d.getMonth()+1;
var year = d.getFullYear();
// FY
if (month > 1) {
var year = year + 1
}
Logger.log("Year: " + year + " month: " + month)
var year = year.toString().substr(2,2);
var fy = "".concat("FY",year);
if (month == 11 || month == 12 || month == 1) {
var Q = "Q4"
}
else if (month <=4) {
var Q = "Q1"
}
else if (month <=7) {
var Q = "Q2"
}
else if (month <=10) {
var Q = "Q3"
}
var fyQ = "".concat(fy," ",Q);
return fyQ;
}
function fQ(date) {
var d = new Date(date);
var month = d.getMonth()+1;
var year = d.getFullYear();
// FY
if (month > 1) {
var year = year + 1
}
Logger.log("Year: " + year + " month: " + month)
var year = year.toString().substr(2,2);
var fy = "".concat("FY",year);
if (month == 11 || month == 12 || month == 1) {
var Q = "Q4"
}
else if (month <=4) {
var Q = "Q1"
}
else if (month <=7) {
var Q = "Q2"
}
else if (month <=10) {
var Q = "Q3"
}
return Q;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment