Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am trying to get the Current and Previous quarters using javascript. Please suggest a function which can fetch me current and previous quarters. Belo is my javascript function to get the current quarter for the current year.

C#
function getQuarter(d) {
            var enterOnce = true;
            d = d || new Date();
            var m = Math.floor(d.getMonth() / 3) + 1; // gives you the current quarter.



            return m > 4 ? m - 5 : m;
        }


Likewise i should get the previous quarters also

XML
function FillDropdownList() {
            var firstListItem = "<option value = '0'>select quarter</option>";
            var currentQuarter = getQuarter(new Date());
            var listOptions = "";
            for (var i = currentQuarter; i; i--) {
                listOptions += "<option value = '" + i + "'>Q" + i + " " + (new Date).getFullYear() + " list" + "</option>";
            }
            listOptions = firstListItem + listOptions;

            // to have short list of options which corresponds to the country
            // from the row we have to change temporary the column property
            $("select#drpQuarter").empty();
            setTimeout(function() { $("select#drpQuarter").html(listOptions); }, 200);
        }


Now my output shows this way :

select quarter
Q1 2014 list

, whereas i want the output as:


select quarter
Q1 2014 list
Q4 2013 list
Q3 2013 list
Q2 2013 list

How can i get this type of output.

Thanks in advance.
Posted

1 solution

 
Share this answer
 
Comments
rav_nan 15-Jan-14 2:10am    
i tried this too but it only returns me the year four quarters and not the previous quarters. So this might not help me out.
rav_nan 15-Jan-14 2:31am    
anybody who can help me out on this issue ASAP?
Karthik_Mahalingam 15-Jan-14 2:52am    
ok sure...
u need the op like this
Q1 2014
Q4 2013
Q3 2013
Q2 2013

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900