How to get last 6 months for the current year in Jquery -


dynamically want generate last 6 months using jquery demo here

var str = ""; var monthnames = [ "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" ];          ( var = 5; >= 0; i--) {              var = new date();             var date = new date(now.setmonth(now.getmonth() - i));             var datex = ("0" + date.getdate()).slice(-2) + "-" + ("0" + (date.getmonth() + 1)).slice(-2) + "-" + date.getfullyear();              str += "date :"+datex+" | month : " + monthnames[date.getmonth()] + "-" + date.getfullyear()+"\n";         } 

above code works fine if current date month less 30th, if current date 31 above code generate duplicate month irrelevant dates.

any appreciated. thanks.

this last paste 6 months current month on words

var str = "<option value=''>---select month---</option>";          var monthnames = [ "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" ];           var vardate = new date();         var month = vardate.getmonth()+1;         var currentday = vardate.getdate();           ( var = 5; >= 0; i--) {              var = new date();             now.setdate(1);             var date = new date(now.setmonth(now.getmonth() - i));             var datex = ("0" + date.getdate()).slice(-2) + "-" + ("0" + (date.getmonth() + 1)).slice(-2) + "-" + date.getfullyear();              str += "<option value='"+datex+"'>" + monthnames[date.getmonth()] + "-" + date.getfullyear() + "</option>";         }          $(".monthlyerrorreports").html(str); 

this number of days / dates of current , previous month

var fullmonthnames = [ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" ];    var dateobject = new date(); var currentmonth = dateobject.getmonth(); var strdatelist = "<option value=''></option>"+"<optgroup label='--"+fullmonthnames[currentmonth]+"--'>"; var noofdatesinmonth = daysinmonth(currentmonth,dateobject.getfullyear()); var varnoofdaysflag = noofdatesinmonth; var varitterationbreakflag = true; var varnoofittecount = 0; var vartotaldayscount = noofdatesinmonth; var currentdate = ("0" + dateobject.getdate()).slice(-2) + "-" + ("0" + (currentmonth+1)).slice(-2) + "-" + dateobject.getfullyear(); var previousday =  new date(new date().setdate(new date().getdate() - 1));     previousday = ("0" + previousday.getdate()).slice(-2) + "-" + ("0" + (previousday.getmonth()+1)).slice(-2) + "-" + previousday.getfullyear();  for(var = 1; <= noofdatesinmonth ; i++){      var dropdownvalue = ("0" + i).slice(-2) + "-" + ("0" + (currentmonth+1)).slice(-2) + "-" + dateobject.getfullyear();      strdatelist += "<option value='"+dropdownvalue+"'>" +("0" + i).slice(-2)+"-"+ monthnames[currentmonth] + "-" + dateobject.getfullyear() + "</option>";      ++varnoofittecount;      if(varnoofdaysflag == && varitterationbreakflag){          dateobject = new date(dateobject.setmonth(dateobject.getmonth() - 1));         currentmonth = (dateobject.getmonth());         noofdatesinmonth = daysinmonth(currentmonth,dateobject.getfullyear());         = 0;         varitterationbreakflag = false;         vartotaldayscount += noofdatesinmonth;         strdatelist += "</optgroup><optgroup label='--"+fullmonthnames[currentmonth]+"--'>";     }      if(vartotaldayscount == varnoofittecount){         noofdatesinmonth = 0;     } }             strdatelist += "</optgroup>";     $(".noofdatelist").html(strdatelist); 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -