sayedsohail Posted May 14, 2007 Share Posted May 14, 2007 Hello everyone, my checkdate function is not working, here is my code, please help. The $_POST['f_date'] is 01/01/70 function checkData($date) { if (!isset($date) || $date=="") { return false; } list($dd,$mm,$yy)=explode("/",$date); if ($dd!="" && $mm!="" && $yy!="") { return checkdate($mm,$dd,$yy); } return false; } if(!$t=checkData($_POST['f_date'])){ echo "Date is wrong";} else { echo "date is right";} Quote Link to comment https://forums.phpfreaks.com/topic/51340-checkdate-function-not-working-please-help/ Share on other sites More sharing options...
obsidian Posted May 14, 2007 Share Posted May 14, 2007 I'm not sure exactly what is wrong with what you're using, but based on the outcome, I'd recommend you use some pattern matching to assure that your entered data is in the proper format before your check. The way you are calling the function also looks very iffy: <?php function checkData($date = '') { if (!preg_match('|^(\d+)/(\d+)/(\d+)\z|', $date, $match)) { return FALSE; } else { return checkdate($match[2], $match[1], $match[3]); } } if (checkData($_POST['f_date'])) { // Date is right } else { // Date is wrong } ?> Keep in mind that this is following your example and expecting the date to be in the format DD/MM/YYYY. Quote Link to comment https://forums.phpfreaks.com/topic/51340-checkdate-function-not-working-please-help/#findComment-252843 Share on other sites More sharing options...
sayedsohail Posted May 14, 2007 Author Share Posted May 14, 2007 I tried the simpliest function, below is the code it keeps on says mysql error check manual. my date field which is f_date have date displayed as 01/01/1970 and on form submit i am trying this function, i have been trying this since morning, stuck. secondly when i tried to display date in human readable format from my sql statement, it just print 01/01/1970, although the date is very recent: here is the code i used to display date in human readable format $fmdate = date('d/m/Y', "$row[model_date]");. Here is my new code for validating date field. list($y, $m, $d) = explode('/', $_POST['f_date']); if(checkdate($m, $d, $y)) { echo 'Good!'; } else { echo 'Bad!'; } Quote Link to comment https://forums.phpfreaks.com/topic/51340-checkdate-function-not-working-please-help/#findComment-252852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.