0

I have this date format: August 22, 2016

I want to convert to 08/22/2016

str_replace is the solution? eg: str_replace("August","08/",$var); but it should have at least 12 str_replaces...

any ideas for a simple way?

RGS
  • 3,760
  • 2
  • 26
  • 54

3 Answers3

5

Refer to DateTime::format

Specify your desired date format 'm/d/Y' after creating the DateTime object.

Try this:

$date = new DateTime('August 22, 2016');
echo $date->format('m/d/Y');  // 08/22/2016
Community
  • 1
  • 1
Object Manipulator
  • 8,644
  • 2
  • 10
  • 31
0

try this,

$originalDate = "August 22, 2016";
$newDate = date("m/d/Y", strtotime($originalDate));
echo $newDate;

OUTPUT

08/22/2016

DEMO

Dave
  • 3,046
  • 7
  • 19
  • 32
0

just like php date function convert to in strtotime,

Example:

$date = "August 22, 2016";
$date2 = date("m/d/Y", strtotime($date));
echo $date2;

ANS : 08/22/2016

Note: if you change date format so change in date function so u like

pawan sen
  • 706
  • 5
  • 14