user5781295
user5781295

Reputation:

Converting a date from bootstrap date picker to fit mysql date

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

Answers (3)

Tri Hoang
Tri Hoang

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

Hassan ALi
Hassan ALi

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

Qrchack
Qrchack

Reputation: 947

Possible duplicate of this, try combining strtotime() and date()

Upvotes: 1

Related Questions