Check if date is legal

Source: Internet
Author: User
Check if date is legal
  1. function Check_date ($date) {//check date is legal date
  2. $DATEARR = Explode ("-", $date);
  3. if (is_numeric ($dateArr [0]) && is_numeric ($DATEARR [1]) && is_numeric ($DATEARR [2])) {//Open source OSPhP.COM.CN
  4. return Checkdate ($DATEARR [1], $DATEARR [2], $DATEARR [0]);
  5. }
  6. return false;
  7. }
  8. function Check_time ($time) {//Check whether the time is legitimate
  9. OSPHP.COM.Cn Open Source
  10. $TIMEARR = Explode (":", $time);
  11. if (is_numeric ($timeArr [0]) && is_numeric ($TIMEARR [1]) && is_numeric ($TIMEARR [2])) {
  12. Open Source Code OSPHP.COM.Cn
  13. if ($timeArr [0] >= 0 && $timeArr [0] <= && ($TIMEARR [1] >= 0 && $timeArr [1] <= 59) && ($TIMEARR [2] >= 0 && $timeArr [2] <= 59))
  14. PHP Open Source Code
  15. return true;
  16. Else
  17. return false;
  18. }
  19. return false;
  20. }
  21. function DateDiff ($date 1, $date 2, $unit = "") {//Time comparison function, return two dates in seconds, minutes, hours or days
  22. Switch ($unit) {
  23. Case ' s ':
  24. $dividend = 1;
  25. Break
  26. Case ' I ':
  27. $dividend = 60;
  28. OSPHP.COM.CN
  29. Break
  30. Case ' H ':
  31. $dividend = 3600;
  32. Break
  33. Case ' d ':
  34. $dividend = 86400;
  35. Break
  36. Default
  37. $dividend = 86400;
  38. }
  39. $time 1 = strtotime ($date 1);
  40. $time 2 = strtotime ($date 2);
  41. if ($time 1 && $time 2)//osphp.com.cn
  42. return (float) ($time 1-$time 2)/$dividend;
  43. return false;
  44. }
  45. ?>
Copy Code
  • Related Article

    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.