I have a date field in php which is using this code:
$date = mysql_real_escape_string($_POST['intake_date']);
How do I convert this to MySql format 0000-00-00 for inclusion in db. Is it along the lines of: date(‘Y-m-d’ strtotime($date);. The reason I ask, is because I have tried variations of this and I cannot seem to get it to work. Either displays as 1970 or some other variation of that. Many thanks
1. If your MySQL column is
DATEtype:2. If your MySQL column is
DATETIMEtype:You haven’t got to work
strototime(), because it will not work with dash-separators, it will try to do a subtraction.Update, the way your date is formatted you can’t use
strtotime(), use this code instead:Output: