Reputation:
How can I convert the bootstrap date-picker date to fit the mysql date. Here is one example how i get the date from my date-picker
"11/16/2016 6:12 AM"
.How can i convert it to this date format
"0000-00-00 00:00:00"
I'm working in php here ,i have came to this part where i need to store this date ,but I'm unable to convert it that it fits the date format from the database. Thanks
Upvotes: 0
Views: 1387
Reputation: 1402
If you use PHP version >= 5.3 or PHP 7, you can do something like this:
$date = date_create_from_format("m/d/Y G:i A", "11/16/2016 6:12 AM");
echo date_format($date, "Y-m-d H-i-s");
And checkout the docs page to see all the format variables.
Upvotes: 1
Reputation: 1331
mysql database needs date format in Y-m-d format so in case to insert this date format in the database you will need to change the date format that comes from datepicker.
user this code to convert
date('Y-m-D',strtotime('YOUR DATEPICKER DATE'));
Upvotes: 0