/** * Get the start date, end date of 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 (); //formatted 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); } //TodayvarGetcurrentdate =NewDate (Nowyear, Nowmonth, nowday);varGetcurrentdate =formatdate (getcurrentdate)//YesterdayvarGetyesterdaydate =NewDate (Nowyear, Nowmonth, nowDay-1);varGetyesterdaydate =formatdate (getyesterdaydate); //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 the end date for this weekfunctiongetweekenddate () {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 end date for this monthfunctiongetmonthenddate () {varMonthenddate =NewDate (Nowyear, Nowmonth, Getmonthdays (Nowmonth)); returnformatdate (monthenddate); } //get start time last monthfunctiongetlastmonthstartdate () {varLastmonthstartdate =NewDate (Nowyear, Lastmonth, 1); returnformatdate (lastmonthstartdate); }//get last month end 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 end date of the quarterfunctiongetquarterenddate () {varQuarterendmonth = Getquarterstartmonth () + 2; varQuarterstartdate =NewDate (Nowyear, Quarterendmonth, Getmonthdays (Quarterendmonth)); returnformatdate (quarterstartdate); }
JS Get the start date, end date
for this week, this quarter, this month, the last month