RE: [PHP] Valid date
| From: | Johnson, Kirk | Date: | Mon, 21 Apr 2003 14:02:38 +0000 |
| Subject: | RE: [PHP] Valid date | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-144635@lists.php.net to get a copy of this message | ||
> using the following script how can i make sure that the date output is
> always a valid date?
>
> $date = '2003-4-23';
> $i = 0;
> while ($i < 10){
> $date++;
> echo "$date<br>";
> $i++;
> }
In the while loop, add this:
$parts = explode('-', $date);
if(checkdate($parts[1], $parts[2], $parts[0])) {
echo "$date<br>";
}
Kirk