Get current Quarter and Fiscal Year ?

I found the code below at this site (http://stackoverflow.com/questions/11981453/get-current-quarter-in-year-with-javascript)

I'm trying to figure out how the code figures out the current quarter base on the Govt. fiscal year.
// For the US Government fiscal year
// Oct-Dec = 1
// Jan-Mar = 2
// Apr-Jun = 3
// Jul-Sep = 4

function getQuarter(d) {
  d = d || new Date();
  var m = Math.floor(d.getMonth()/3) + 2;
  return m > 4? m - 5 : m;
}

Also, how would I get the current fiscal year?
LVL 5
IsaacSharePoint Client Side DeveloperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Rainer JeschorConnect With a Mentor Commented:
Hi
should be
var fiscalYear;
if (d.getMonth() > 8)
{ fiscalYear = d.getFullYear() + 1;} else { fiscalYear = d.getFullYear();}

HTH
Rainer
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
Hi Rainer,

could you please explain what you are checking for?
>>if(d.getMonth()>8)<<

Shouldn't it be 9 instead of 8?
0
 
Rainer JeschorCommented:
Hi,
no because Javascript date object starts the month enumeration with 0
0=January
...
8=September
http://www.w3schools.com/jsref/jsref_getmonth.asp
Therefore I check if it is October to December because then its the next fiscal year (year+1).

HTH
Rainer
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Rainer JeschorCommented:
And your above formula should be incorrect as it would return 0 for months October to December:
9/3 = 3
3+2=5
5-5=0

So it should be
  return m > 4? m - 4 : m;

I am on the road therefore no coding environment to double check.
0
 
Rainer JeschorCommented:
Hi,
here the "proof": http://jsfiddle.net/EE_RainerJ/ALeMU/

HTH
Rainer
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.