1

Use date()

$sqldate = "2016-07-18";
$newDate = date("d-m-Y",$sqldate);

I also use

implode('-', array_reverse(explode('/', $sqldate)));

I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in SQL); however I don't know how the date function requires a timestamp, and I can't get a timestamp from this string.

I am getting particular date format. WHY? I tried get a date expected format, i tried php date but no success..

I excpected output

18/07/2016

3 Answers3

1

Use strtotime().

$sqldate = "2016-03-21";
echo $newDate = date("d/m/Y",  strtotime($sqldate));

Output

21/03/2016

Live Demo : Click Here

RJParikh
  • 4,110
  • 1
  • 18
  • 35
1
$sqldate = "2016-03-21";
$newDate = date("d-m-Y",strtotime($sqldate));

this is what you need.

Raymond Cheng
  • 2,275
  • 18
  • 32
1
 $sqldate = "2016-03-21";
 echo date('d/m/Y', strtotime($sqldate));
Pradeep
  • 9,481
  • 13
  • 27
  • 34