Reply to Re: Checking a date for validity

Your name:

Reply:


Posted by JamesBenson on 09/08/05 05:01

I would use something like:-



$date = '09/09/2005';

list($month, $day, $year) = explode("/", $date);

if(checkdate($month, $day, $year)) {
/* valid date */
} else {
/* invalid date */
}






Todd Cary wrote:
> I need to check the input of a user to make sure the date is valid and
> correctly formatted. Are there any examples available?
>
> Here is one solution I created:
>
> /* Is date good */
> function is_date_good($date) {
> if (strtotime($date) == -1) {
> $retval = 0;
> } else {
> if (strpos($date, "/") > 0) {
> $parts = explode("/", $date);
> } elseif (strpos($date, "-") > 0) {
> $parts2 = explode("-", $date);
> $parts[0] = $parts2[1];
> $parts[1] = $parts2[2];
> $parts[2] = $parts2[0];
> } else {
> $parts = explode(".", $date);
> }
> //print_r($parts);
> if (checkdate($parts[0], $parts[1], $parts[2]) )
> return 1;
> else
> return 0;
> }
> return $retval;
> }
>
> Is there a simplier solution?
>
> Many thanks......

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация