-2

I have a simple section in which a user can select a range of date.

PHP to get these dates from datepicker

if (isset($_POST['from_date']) && isset($_POST['to_date'])) {
  $firstDate= $_POST['from_date'];
  $lastDate= $_POST['to_date'];
   var_dump($firstDate);
   var_dump($lastDate);

}

From the above PHP script, I am getting this

string(10) "08/13/2019"
string(10) "08/14/2019"

But I want this

string(10) "2019-08-13"
string(10) "2019-08-14"

What do I need to do to achieve what I want?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
The Dead Man
  • 6,258
  • 28
  • 111
  • 193

1 Answers1

0

You can use strtotime() :

$time = strtotime('08/13/2019');

$newformat = date('Y-m-d',$time);

echo $newformat;
// 2019-08-13
shllaku360
  • 71
  • 3