note 16812 deleted from function.checkdate by jimw

From: Date: Fri, 07 Dec 2001 20:43:27 +0000
Subject: note 16812 deleted from function.checkdate by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-21947@lists.php.net to get a copy of this message
I put this function in my common include file. It is an enhancment of the one above. It is very handy for all sorts of date/time validation from user input fields. Example inputs: 12/5/01 12/5/01 19:24:05 5/6/2001 5:56:24 etc will return true, whereas: 13/5/01 12/53/01 19:24:05 12/5/01 25:53:12 etc will return false. (please excuse the lack of indents) function IsDateTime($input){ if (strpos($input,'/')>0 and strpos($input,' ')>0 and strpos($input,':')>0) { $tmpdata=explode(' ',$input); $data1=explode('/',$tmpdata[0]); $data2=explode(':',$tmpdata[1]); $m=$data1[0]; $d=$data1[1]; $y=$data1[2]; $H=$data2[0]; $M=$data2[1]; $S=$data2[2]; $res1=checkdate($m,$d,$y); $res2=strtotime("$m/$d/$y $H:$M:$S"); } else { if (strpos($input,'/')>0) $data1=explode('/',$input); elseif (strpos($input,'-')>0) $data1=explode('-',$input); elseif (strpos($input,'.')>0) $data1=explode('.',$input); else $data1=''; $m=$data1[0]; $d=$data1[1]; $y=$data1[2]; $res1=checkdate($m,$d,$y); $res2 = 1; } if ($res1 and $res2 > 0) { return true;} else { return false;} } PS: If you know a better function to use to return TRUE or FALSE if a certain character exists in a string or not, then use it instead of what I used above, which is: strpos($string,'char')>0 It works... but really is kind of a hack.

« previous php.notes (#21947) next »