-1

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

Ankur Tiwari
  • 2,762
  • 2
  • 23
  • 40

2 Answers2

3

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

Demo on 3v4l.org

Nick
  • 138,499
  • 22
  • 57
  • 95
2

You need to replace / with -

 date('m/Y', strtotime(str_replace('/','-',$_POST`['card_form_plan_start_date'])))
Omi
  • 3,954
  • 5
  • 21
  • 41