-1

My form inputs a date as dd/mm/yyyy, however my database uses a yyyy-mm-dd format. How do I flip the dates into the database format along with the difference of '/' and '-'?

$first_date = $_REQUEST["date_1"];
Ryan
  • 5
  • 2

2 Answers2

1

You can simply use:

$date = date('Y-m-d H:i:s', strtotime($first_date);
sergio
  • 5,210
  • 7
  • 24
  • 46
0

You can use PHP's datetime class:

$dateTime = new DateTime($first_date);
$dateTime = $dateTime->format('Y-m-d');
Daan
  • 12,099
  • 6
  • 34
  • 51