Solved

Get current Quarter and Fiscal Year ?

Posted on 2013-06-08
6
1,032 Views
Last Modified: 2013-06-08
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?
0
Comment
Question by:Isaac
  • 4
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39231871
Hi
should be
var fiscalYear;
if (d.getMonth() > 8)
{ fiscalYear = d.getFullYear() + 1;} else { fiscalYear = d.getFullYear();}

HTH
Rainer
0
 
LVL 5

Author Comment

by:Isaac
ID: 39231880
Hi Rainer,

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

Shouldn't it be 9 instead of 8?
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39231905
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39231912
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
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39232175
Hi,
here the "proof": http://jsfiddle.net/EE_RainerJ/ALeMU/

HTH
Rainer
0
 
LVL 5

Author Closing Comment

by:Isaac
ID: 39232220
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript: Issue with onClick 5 36
Apply tab index in forms 6 37
Why my select dropdown does not work? 8 28
how can i select 4 13
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now