JS to determine the difference of two dates or to determine the size of two dates

Source: Internet
Author: User

  1. Determine the difference between two dates
  2. function DateDiff (sdate1,sdate2) {
  3. The format of sDate1 and SDate2 is xxxx-xx-xx
  4. var adate,odate1,odate2,idays;
  5. Convert to XX-XX-XXXX format
  6. Adate = Sdate1.split ("-");
  7. oDate1 = new Date (adate[1] + "," + adate[2] + "," + adate[0]);
  8. Adate = Sdate2.split ("-");
  9. ODate2 = new Date (adate[1] + "," + adate[2] + "," + adate[0]);
  10. Alert (sDate1 + "=====" + sDate2 + "= =" + oDate1 + "= = =" + ODate2);
  11. Alert ("--------" + (Odate1-odate2));
  12. Converts the difference in milliseconds to days
  13. Idays = parseint (Math.Abs (odate1-odate2)/1000/60/60/24);
  14. return idays;
  15. Determine the size of two dates
  16. function Checkdate () {
  17. 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
  18. It's a good judgment to judge.
  19. var S1 = document.getelementbyidx_x ("Txtstart"). Value;
  20. var s2 = document.getelementbyidx_x ("Txtend"). Value;
  21. alert (S1);
  22. alert (S2);
  23. var sdate = new Date (S1.replace (/\-/g, '/'));
  24. var eDate = new Date (S2.replace (/\-/g, '/'));
  25. Alert (sdate + "=============" + eDate);
  26. if (Sdate > EDate)
  27. {
  28. Alert ("The end date cannot be less than the start date ");
  29. return false;
  30. }
  31. return true;

JS to determine the difference of two dates or to determine the size of two dates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.