/**
* Get the start date, stop date for this week, this quarter, this month, last month
*/
var now = new Date (); Current date
var nowdayofweek = Now.getday (); The day of the week today
var nowday = Now.getdate (); Current day
var nowmonth = Now.getmonth (); Current month
var nowyear = Now.getyear (); When the year before
Nowyear + = (Nowyear < 2000)? 1900:0; //
var lastmonthdate = new Date (); Last month date
Lastmonthdate.setdate (1);
Lastmonthdate.setmonth (Lastmonthdate.getmonth ()-1);
var lastyear = Lastmonthdate.getyear ();
var lastmonth = Lastmonthdate.getmonth ();
Format Date: YYYY-MM-DD
function FormatDate (date) {
var myyear = Date.getfullyear ();
var mymonth = Date.getmonth () +1;
var myweekday = 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 month
function Getmonthdays (mymonth) {
var monthstartdate = new Date (Nowyear, Mymonth, 1);
var monthenddate = new Date (nowyear, Mymonth + 1, 1);
var days = (monthenddate-monthstartdate)/(1000 * 60 * 60 * 24);
return days;
}
Get the start month of the quarter
function Getquarterstartmonth () {
var quarterstartmonth = 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;
}
return quarterstartmonth;
}
Get the start date for this week
function Getweekstartdate () {
var weekstartdate = new Date (nowyear, Nowmonth, Nowday-nowdayofweek);
return FormatDate (weekstartdate);
}
Get this week's stop date
function Getweekenddate () {
var weekenddate = new Date (nowyear, Nowmonth, Nowday + (6-nowdayofweek));
return FormatDate (weekenddate);
}
Get the start date for this month
function Getmonthstartdate () {
var monthstartdate = new Date (Nowyear, Nowmonth, 1);
return FormatDate (monthstartdate);
}
Get the stop date for this month
function Getmonthenddate () {
var monthenddate = new Date (nowyear, Nowmonth, Getmonthdays (Nowmonth));
return FormatDate (monthenddate);
}
Get started last month
function Getlastmonthstartdate () {
var lastmonthstartdate = new Date (Nowyear, Lastmonth, 1);
return FormatDate (lastmonthstartdate);
}
Get last month stop time
function Getlastmonthenddate () {
var lastmonthenddate = new Date (nowyear, Lastmonth, Getmonthdays (Lastmonth));
return FormatDate (lastmonthenddate);
}
Get the start date for the quarter
function Getquarterstartdate () {
var quarterstartdate = new Date (Nowyear, Getquarterstartmonth (), 1);
return FormatDate (quarterstartdate);
}
or the stop date for this quarter
function Getquarterenddate () {
var quarterendmonth = Getquarterstartmonth () + 2;
var quarterstartdate = new Date (nowyear, Quarterendmonth, Getmonthdays (Quarterendmonth));
return FormatDate (quarterstartdate);
}
JS Get Time (this week, this quarter, this month ...)