/**
* Convert dates to YYYY-MM format.
* Help verify that two times are in the same year of the month
* @param datestr
*/
function Formatyearmonth (b_date) {
var b_date_year = B_date.getyear ();
var b_date_month = B_date.getmonth () +1;
if (B_date_month < 10) {
B_date_month = "0" + b_date_month;
}
return b_date_year + "" + b_date_month;
}
function Getdatesub (date_b,date_e) {
The following must have, otherwise it will be but a Nan
var b_date = new Date (Date.parse (Date_b.replace (/-/g, '/')));
var e_date = new Date (Date.parse (Date_e.replace (/-/g, '/')));
var b_year_month = Formatyearmonth (b_date);
var e_year_month = Formatyearmonth (e_date);
if (b_year_month! = e_year_month) {
Alert ("Please keep the start and end dates of the stops within the same month.") ");
return-1;
}
Return parseint (Math.Abs ((e_date-b_date)/86400000) + 1;
}
/**
* Verify that the start date to the end date must be the same as one months
*/
function Validatedate () {
var date_b = form. Begin_date.value;
var date_e = form. End_date.value;
Verify date format
if (!isdate (Date_b)) {
Alert (the Stop start date is not a valid date yyyy-mm-dd. ");
return false;
}
if (!isdate (date_e)) {
Alert (the stop end date is not a valid date yyyy-mm-dd. ");
return False
}
if (Date_b > Date_e) {
Alert ("The starting time of the stop start date cannot be later than the end Time");
return false;
}
Start calculating two date difference values (1-31 is 31 days, not 30 days. )
var datesub = getdatesub (date_b,date_e);
if (datesub = =-1) {
return false;
}
Form. Tc_days.value = datesub;
return true;
}
JS Verify that two dates are the same month, and calculate the number of days difference