Приглашаем посетить
Добычин (dobychin.lit-info.ru)

Validating a Date

Previous
Table of Contents
Next

Validating a Date

checkdate(2, 29, 2000)


When you get a datefor example, from the user using an HTML formthis data must be validated. This includes checking whether the month exists and if the month has enough days. If it's February, you might also want to find out whether it is a leap year.

Validating Date Information (checkdate.php)
<?php
  echo '2000 was ' .
    (checkdate(2, 29, 2000) ? 'a' : 'no') .
    ' leap year.<br />';
  echo '2100 will be ' .
    (checkdate(2, 29, 2100) ? 'a' : 'no') .
    ' leap year.';
?>

But PHP would not be PHP if you really had to do this on your own. The function checkdate() validates a date; you provide the month, the day, and the year as parameters.


Previous
Table of Contents
Next