-1

We have a current date format is 02-05-15 and the output that I want is 02/05/2015 in PHP.

Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54

4 Answers4

1

Use DateTime

$myDateTime = DateTime::createFromFormat('d-m-y', "02-05-15");
echo  $myDateTime->format('d/m/Y');
// Output : 02/05/2015

Note:

You may also want to set the default timezone before using DateTime, i.e.:

date_default_timezone_set("Europe/Lisbon");

For date_and_time and other php best practices visit:

http://www.phptherightway.com/#date_and_time

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
0

You can do this in this way

$sections      = explode('-','02-05-15');
$formated_date = $sections[0]."/".$sections[1]."/20".$sections[2];

hope this will help

Janaka
  • 398
  • 5
  • 16
0

The following code should do the trick:

<?php
   $time = mktime(0,0,0, '02', '05', '15'); 
   //OR mktime(0,0,0, '05', '02', '15'); //depending on the expected format
   echo date("d/m/Y",$time); //assuming the above date is 2 May 2015
   //alternatively it would be
   echo date('m/d/Y', $time); //if the above date is 5 February 2015
?>
Tash Pemhiwa
  • 7,590
  • 4
  • 45
  • 49
-1

You can use

$date = "02-05-15";
$format_date = date('m/d/Y', strtotime($date));

For more details about formats, please refer this

Ravneet
  • 300
  • 1
  • 5