How can I get the current quarter we are in with javascript? I am trying to detect what quarter we are currently in, e.g. 2.
EDIT And how can I count the number of days left in the quarter?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Given that you haven’t provided any criteria for how to determine what quarter “*we are currently in”, an algorithm can be suggested that you must then adapt to whatever criteria you need. e.g.
As a runnable snippet and including the year:
You can then adapt that to the various financial or calendar quarters as appropriate. You can also do:
Then use different
qarrays depending on the definition of quarter required.Edit
The following gets the days remaining in a quarter if they start on 1 Jan, Apr, Jul and Oct, It’s tested in various browsers, including IE 6 (though since it uses basic ECMAScript it should work everywhere):