jenniferG Posted September 8, 2007 Share Posted September 8, 2007 we are trying to determine ikf a date from a mysql database is either null or equal to '0000-00-00'; what we tried is below and it does not appear to do what we need. If the date is either null or ='0000-00-00', want a return=0, else return 1. Thanks, melanie function check_valid_date($DATE){ /* designed to see if a date is either null or if it is equal to default value = '0000-00-00' returns 0 if $date is null or =default */ $DATE=trim($DATE); $CHECK1 =is_null($DATE); $CHECK2 = strcmp($DATE,'0000-00-00'); if ($CHECK1 ==1 || $CHECK2 == 0){return 0;}else {return 1;} }//check_valid_date Quote Link to comment https://forums.phpfreaks.com/topic/68482-validate-date/ Share on other sites More sharing options...
benjaminbeazy Posted September 8, 2007 Share Posted September 8, 2007 this uses checkdate, based on how you date is formatted, change the parameters accordingly checkdate(month, day, year) using your date schema, YEAR-MONTH-DAY is checkdate($date_parts[1], $date_parts[2], $date_parts[0]) function check_valid_date($date){ $date = trim($date); $date_parts = explode("-", $date); if( checkdate($date_parts[1], $date_parts[2], $date_parts[0]) ){ return 0; } return 1; } Quote Link to comment https://forums.phpfreaks.com/topic/68482-validate-date/#findComment-344264 Share on other sites More sharing options...
benjaminbeazy Posted September 10, 2007 Share Posted September 10, 2007 how did it work??! Quote Link to comment https://forums.phpfreaks.com/topic/68482-validate-date/#findComment-345148 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.