First use the this function to validate the date what we will be getting after hitting post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | function _date_is_valid($str) { if (substr_count($str, '-') == 2) { list($y, $m, $d) = explode('-', $str); if(checkdate($m, $d,sprintf('%04u', $y))){ return true; }else{ return false; }} return false; } |
Then prepare the date for Mysql data insertion
1 | $date = date('Y-m-d', strtotime(str_replace('-', '/', $_POST['date']))); |
Disqus comments