-1

How to change the normal input date format dd-mm-yyyy in the webpage to yyyy-mm-dd while storing in the php my admins

Raja Manickam
  • 1,743
  • 4
  • 20
  • 28

2 Answers2

3

you can convert the date with strtotime();

  $dateToday = date("d-m-Y");
    $newDate = date("Y-m-d", strtotime($dateToday));

And then you can store data to your database.

Akhil Clement
  • 575
  • 1
  • 7
  • 17
2

Although you can use strtotime, I much prefer DateTime object.

//The second parameter being the string from the database.
$date = DateTime::createFromFormat('d-m-Y', '27-10-2014');
echo $date->format('Y-m-d');
ʰᵈˑ
  • 11,279
  • 3
  • 26
  • 49