Posted By

sekihin on 05/04/09


Tagged

php date


Versions (?)

check Date Format


 / Published in: PHP
 

  1. /*
  2. 解説:指定した文字列が有効な時刻を含むかどうかを調べます
  3. 引数:
  4.   $value チェック対象日付文字列
  5. 返り値:
  6.   チェック結果
  7. */
  8. function checkDateFormat($value)
  9. {
  10. $value = str_replace("/","-",$value);
  11. //match the format of the date
  12. if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $value, $parts))
  13. {
  14. //check weather the date is valid of not
  15. if(checkdate($parts[2],$parts[3],$parts[1]))
  16. return true;
  17. else
  18. return false;
  19. }
  20. else
  21. return false;
  22. }
  23. echo checkDateFormat("2008/02/29"); //return true
  24. echo checkDateFormat("2007/02/29"); //return false

Report this snippet  

You need to login to post a comment.