Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Is there anyway to find which quarter(fiscal period) of a given date?

narendrad
Kilo Contributor

Is there any OOB functionality or scripts to find the quarter(fiscal period) of a given date?

For example, if I pass current date(08/23/2017), I should see the quarter number like Q3.2017 as a result in return.

6 REPLIES 6

Patrick Fedigan
Giga Guru

Hello,



I have come up with a simple javascript function that returns the fiscal date in a small fiddle below.



Fiscal Date - JSFiddle



Cheers,


Dennis R
Tera Guru

I'd probably go this route:



var gDate = new GlideDate();


gDate.setValue('2017-08-23');


var quarter = 'Q' + (Math.floor((gDate.getMonth() - 1) / 3) + 1) + '.' + gDate.getYear();



Feel free to tweak it to customize the exact appearance, of course.



Hope this helps,


--Dennis R



Edit: Ninja'd by Patrick. I think we used the same methodology.  


Harsh Vardhan
Giga Patron

Hi



here is the below server side query.



var today = new Date();


//gs.print(today);


var month = today.getMonth();


//gs.print(month);


var quarter;


if (month < 4)


  quarter = 1;


else if (month < 7)


  quarter = 2;


else if (month < 10)


  quarter = 3;


else if (month < 13)


  quarter = 4;


gs.print(quarter);


Plamen Nakov
Giga Contributor

This might help you 

new global.FinancialsForPPM().getFiscalPeriod('2019-03-03 12:00:00');
 
getFiscalPeriod will return fiscal period based on fiscal unit you are currently using.