For example, "2017-04-01 23:00:00" is Saturday, "2017-04-28 23:00:00" is Friday, including the week of their respective, I really need to get the result is 5 weeks.
Started to do when the string ah, time format ah, and then found that there is absolutely no need, after all, I want only the period value just ....
The idea is really simple, is to get the start date of the week of the Monday date
Then use the Monday date and end date to compare, rounding up. We can get to this number.
varStart = "2017-04-01 23:00:00"; varEnd = "2017-04-28 23:00:00"; //start date of Monday varMonday =showweekfirstday (start); //period difference between the start date's Monday distance end date varCycle =WEEKSBETW (Monday, end); //returns the first day of the week of Nowdate functionShowweekfirstday (nowdates) {varNowdate =NewDate (nowdates); varWeekfirstday =NewDate (Nowdate-(Nowdate.getday ()-1) * 86400000); returnWeekfirstday; }
Returns the number of weeks between two dates
function Weeksbetw (DATE11, Date22) {
var date1 = new Date (DATE11);
var date2 = new Date (DATE22);
The date1,date2 here are all date objects.
var dt1 = Date1.gettime ();
var DT2 = Date2.gettime ();
Rounding up
Return Math.ceil (Math.Abs (DT1-DT2)/1000/60/60/24/7);
}
Above ~
Js-gets the week of two string dates