0
$date = 21/10/2015

And I want the date in 2015-10-21 (y-m-d) format.

I tried:

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

But it only works for dates less than 12.

Kostas Mitsarakis
  • 4,772
  • 3
  • 23
  • 37
bhuwan
  • 105
  • 1
  • 1
  • 7
  • Its working in less than 12 because its treating 21 as month. mm/dd/yyyy is a valid format. dd/mm/yyyy is invalid. Explode like `$dates = explode('/', $date);` and then use mktime like `$date = date("Y-m-d", mktime(0, 0, 0, $dates[1], $dates[0], $dates[2]));` – Ashish Choudhary Oct 20 '15 at 12:37
  • [Valid date formats for strtotime()](http://www.php.net/manual/en/datetime.formats.date.php)... note the differences between using `/` and `-` as separators – Mark Baker Oct 20 '15 at 12:47

0 Answers0