I have a form within which a date is input in UK format, and I need to convert it to
yyyy-mm-dd
e.g. a date entered is: 31/03/2013
which I want to convert to '2013-03-31'
for database insert.
I'm using the following which bizarrely works only sometimes:
$dateInput = $mysqli->real_escape_string($_POST['date']);
$show_date = date('Y-m-d', strtotime($dateInput));
Is there a better way to do this?
Try this :
$dte = '28/03/2013';
$dt = new DateTime();
$date = $dt->createFromFormat('d/m/Y', $dte);
echo $date->format('Y-m-d');
Output: 2013-03-28
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With