Posted By

estebant on 05/11/08


Tagged

date


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dyesin


Function to validate date format in PHP


 / Published in: PHP
 

  1. function checkDateFormat($date)
  2. {
  3. //match the format of the date
  4. if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $date, $parts))
  5. {
  6. //check weather the date is valid of not
  7. if(checkdate($parts[2],$parts[3],$parts[1]))
  8. return true;
  9. else
  10. return false;
  11. }
  12. else
  13. return false;
  14. }
  15.  
  16. echo checkDateFormat("2008-02-29"); //return true
  17. echo checkDateFormat("2007-02-29"); //return false

Report this snippet  

You need to login to post a comment.