Check whether the date is valid

Source: Internet
Author: User
Tags date1
Check whether the date is valid
Check whether the date is valid

  1. Function check_date ($ date) {// check whether the date is valid
  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 valid
  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] <= 23) & ($ 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 ($ date1, $ date2, $ unit = "") {// Time comparison function, returns the seconds, minutes, hours, or days of difference between two dates
  22. Switch ($ unit ){
  23. Case's ':
  24. $ Pidend = 1;
  25. Break;
  26. Case 'I ':
  27. $ Pidend = 60;
  28. // OSPHP. COM. CN
  29. Break;
  30. Case 'H ':
  31. $ Pidend = 3600;
  32. Break;
  33. Case 'D ':
  34. $ Pidend = 86400;
  35. Break;
  36. Default:
  37. $ Pidend = 86400;
  38. }
  39. $ Time1 = strtotime ($ date1 );
  40. $ Time2 = strtotime ($ date2 );
  41. If ($ time1 & $ time2) // OSPHP.com. CN
  42. Return (float) ($ time1-$ time2)/$ pidend;
  43. Return false;
  44. }
  45. ?>

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.