0

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

  • 2
    Possible duplicate of [Convert one date format into another in PHP](http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Qrchack Nov 16 '16 at 17:52

3 Answers3

1

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

Community
  • 1
  • 1
Qrchack
  • 899
  • 1
  • 10
  • 20
1

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.

Tri Hoang
  • 1,262
  • 1
  • 9
  • 6
0

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'));

Hassan ALi
  • 1,313
  • 1
  • 23
  • 51