- Determine the difference between two dates
- function DateDiff (sdate1,sdate2) {
- The format of sDate1 and SDate2 is xxxx-xx-xx
- var adate,odate1,odate2,idays;
- Convert to XX-XX-XXXX format
- Adate = Sdate1.split ("-");
- oDate1 = new Date (adate[1] + "," + adate[2] + "," + adate[0]);
- Adate = Sdate2.split ("-");
- ODate2 = new Date (adate[1] + "," + adate[2] + "," + adate[0]);
- Alert (sDate1 + "=====" + sDate2 + "= =" + oDate1 + "= = =" + ODate2);
- Alert ("--------" + (Odate1-odate2));
- Converts the difference in milliseconds to days
- Idays = parseint (Math.Abs (odate1-odate2)/1000/60/60/24);
- return idays;
- }
- Determine the size of two dates
- function Checkdate () {
- To get the date value and convert it into a date format, replace (/\-/g, "/") is the date-to -date format based on the validation expression, which
- It's a good judgment to judge.
- var S1 = document.getelementbyidx_x ("Txtstart"). Value;
- var s2 = document.getelementbyidx_x ("Txtend"). Value;
- alert (S1);
- alert (S2);
- var sdate = new Date (S1.replace (/\-/g, '/'));
- var eDate = new Date (S2.replace (/\-/g, '/'));
- Alert (sdate + "=============" + eDate);
- if (Sdate > EDate)
- {
- Alert ("The end date cannot be less than the start date ");
- return false;
- }
- return true;
- }
JS to determine the difference of two dates or to determine the size of two dates