I have a string mm-dd-yyyy which i get from a form, which i want to store it in the database of the data-type DATE (yyyy-mm-dd).
How do i format the string and save it in the database ?
$new_format = date("Y-m-d", strtotime('04-28-2012'));
or
$date = new DateTime('04-28-2012');
$new_format = $date->format('Y-m-d');
or in PHP 5.5+
$new_format = (new DateTime('04-28-2012'))->format('Y-m-d');
Try
$date = DateTime::createFromFormat("m-d-Y", '02-15-2012');
echo $date->format('Y-m-d H:i:s') , "\n";
Output
2012-02-15 23:54:52
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