0

I am storing date in yyyy-mm-dd in database. Now i want to display that date in frontend but while displaying date it should be in dd-mm-yyyy format. How to display it in this format please help <?php echo $data2['emp_dob'];?> . I dont want to change my current format of storing date in yyyy-mm-dd. please help me to display it in dd-mm-yyyy format only

Jens
  • 63,364
  • 15
  • 92
  • 104
mahadev sutar
  • 163
  • 2
  • 14

6 Answers6

5
date('d-m-Y',strtotime($Your_date));
GYaN
  • 2,303
  • 4
  • 18
  • 37
1

I don't think it's strictly correct to say that you're storing dates in your MySQL database as yyyy-mm-dd. The internal representation may be something very different than this, but in any case your real question is how to format the date in a certain way. One option is to handle this in your actual MySQL query using DATE_FORMAT(), e.g.

SELECT DATE_FORMAT(date_col, '%d-%m-%Y')
FROM yourTable
Tim Biegeleisen
  • 451,927
  • 24
  • 239
  • 318
0
if (preg_match("/([0-9]{4})\-([0-9]{2})\-([0-9]{2})/", $data2['emp_dob'], $rg))
  $data2['emp_dob'] = $rg[3]."-".$rg[2]."-".$rg[1]
diavolic
  • 714
  • 1
  • 4
  • 5
0
<?php
  $ddmmyyyy = date("d-m-Y", strtotime($data2['emp_dob']));
?>
MarcoS
  • 16,647
  • 23
  • 89
  • 161
0

<?php echo date("d-m-Y",strtotime($data2['emp_dob']));?>
0

use this function, which uses inbuilt function 'substr(str,start,length)'.

function getFormatDate($date){
    $date = substr($date,8,2).'-'.substr($date,5,2).'-'.substr($date,0,4);
    return $date;
}

getFormatDate($data2['emp_dob']);
reoxey
  • 654
  • 1
  • 6
  • 18
  • `echo date("d-m-Y", strtotime($data2['emp_dob']));` You can pass date format specifier to make date format using `date()` Function. Here is the doc http://php.net/manual/en/function.date.php – Sumon Sarker Mar 27 '17 at 07:20