Now I'm having a date like this, April/2019
. I wanted to convert it into 04/2019
in php. How to resolve this?
date('m/Y', strtotime($_POST`['card_form_plan_start_date']))
What I Wanted - 04/2019 Actual Result - 01/1970
Now I'm having a date like this, April/2019
. I wanted to convert it into 04/2019
in php. How to resolve this?
date('m/Y', strtotime($_POST`['card_form_plan_start_date']))
What I Wanted - 04/2019 Actual Result - 01/1970
strtotime
won't recognise April/2019
as a date. Instead, you can use date_create_from_format
with the F/Y
format, then reformat the output as m/Y
:
echo date_create_from_format('F/Y', 'April/2019')->format('m/Y');
Output
04/2019
You need to replace /
with -
date('m/Y', strtotime(str_replace('/','-',$_POST`['card_form_plan_start_date'])))