php - Format the formatted date for mysql -


how can format date 01 august, 15 mysql date field. need 2015-08-01 format 01 august, 15 format in php. tried following not work

echo date('y-m-d',strtotime('01 august, 15')); 

it because strtotime() not understand 01 august, 15 means. try it:

var_dump(strtotime('01 august, 15')); // false 

the 15 @ end ambiguous; day of month or short year.

the easiest way make work use datetime::createfromformat, so:

$date   = '01 august, 15'; $parsed = datetime::createfromformat('d f, y', $date); echo $parsed->format('y-m-d'); 

if control format of date make easier parse. formatting 01 august 2015 work, example.


Comments