JS Code/** * Get the start date and stop date for this week, this quarter, this month, last month*/ varnow =NewDate ();//Current DatevarNowdayofweek = Now.getday ();//the day of the week todayvarNowday = Now.getdate ();//Current DayvarNowmonth = Now.getmonth ();//Current MonthvarNowyear = Now.getyear ();//Current yearNowyear + = (Nowyear < 2000)? 1900:0;//varLastmonthdate =NewDate ();//Last month dateLastmonthdate.setdate (1); Lastmonthdate.setmonth (Lastmonthdate.getmonth ()-1); varLastYear =lastmonthdate.getyear ();varLastmonth =lastmonthdate.getmonth ();//Format Date: Yyyy-mm-ddfunctionformatdate (date) {varMyyear =date.getfullyear ();varMymonth = Date.getmonth () +1; varMyweekday =date.getdate ();if(Mymonth < 10) {Mymonth= "0" +Mymonth;} if(Myweekday < 10) {Myweekday= "0" +Myweekday;} return(myyear+ "-" +mymonth + "-" +myweekday); }//get the number of days in a monthfunctionGetmonthdays (mymonth) {varMonthstartdate =NewDate (Nowyear, Mymonth, 1); varMonthenddate =NewDate (nowyear, Mymonth + 1, 1); varDays = (monthenddate-monthstartdate)/(1000 * 60 * 60 * 24);returnDays ;}//get the start month of the quarterfunctionGetquarterstartmonth () {varQuarterstartmonth = 0; if(nowmonth<3) {Quarterstartmonth= 0; } if(2<nowmonth && nowmonth<6) {Quarterstartmonth= 3; } if(5<nowmonth && nowmonth<9) {Quarterstartmonth= 6; } if(nowmonth>8) {Quarterstartmonth= 9; } returnQuarterstartmonth;}//get the start date for this weekfunctiongetweekstartdate () {varWeekstartdate =NewDate (Nowyear, Nowmonth, Nowday-Nowdayofweek); returnformatdate (weekstartdate);}//get this week's stop datefunctiongetweekenddate () {varWeekenddate =NewDate (Nowyear, Nowmonth, Nowday + (6-Nowdayofweek)); returnformatdate (weekenddate);}//get the start date for this monthfunctiongetmonthstartdate () {varMonthstartdate =NewDate (Nowyear, Nowmonth, 1); returnformatdate (monthstartdate);}//get the stop date for this monthfunctiongetmonthenddate () {varMonthenddate =NewDate (Nowyear, Nowmonth, Getmonthdays (Nowmonth));returnformatdate (monthenddate);}//get started last monthfunctiongetlastmonthstartdate () {varLastmonthstartdate =NewDate (Nowyear, Lastmonth, 1); returnformatdate (lastmonthstartdate);}//get last month stop timefunctiongetlastmonthenddate () {varLastmonthenddate =NewDate (Nowyear, Lastmonth, Getmonthdays (Lastmonth));returnformatdate (lastmonthenddate);}//get the start date for the quarterfunctiongetquarterstartdate () {varQuarterstartdate =NewDate (Nowyear, Getquarterstartmonth (), 1); returnformatdate (quarterstartdate);}//or the stop date for this quarterfunctiongetquarterenddate () {varQuarterendmonth = Getquarterstartmonth () + 2; varQuarterstartdate =NewDate (Nowyear, Quarterendmonth, Getmonthdays (Quarterendmonth));returnformatdate (quarterstartdate);}
JS get this week, this quarter, this month, the last month's start date, stop date