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
  • 4,062
  • 4
  • 31
  • 67

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
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32
0

try this,

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

OUTPUT

08/22/2016

DEMO

Dave
  • 3,073
  • 7
  • 20
  • 33
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
  • 716
  • 5
  • 14