Posted By

stz184 on 10/21/10


Tagged

date check validate


Versions (?)

Validate date


 / Published in: PHP
 

Check date with format YYYY-MM-DD is valid date in the past. Useful for birthday check - you can't specify birth date in the future, right?

  1. function is_date($date) {
  2. $d = explode('-', $date);
  3. if(count($d) != 3) {
  4. return false;
  5. }
  6. else {
  7. if(is_numeric($d[0]) && is_numeric($d[1]) && is_numeric($d[2])) {
  8. if(checkdate($d[1], $d[2], $d[0])) {
  9. if(strtotime($date) > time()){
  10. return false;
  11. }
  12. else {
  13. return true;
  14. }
  15. }
  16. else {
  17. return false;
  18. }
  19. }
  20. else {
  21. return false;
  22. }
  23. }
  24. }

Report this snippet  

You need to login to post a comment.