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
  • 67,715
  • 15
  • 98
  • 113
mahadev sutar
  • 171
  • 2
  • 16

6 Answers6

5
date('d-m-Y',strtotime($Your_date));
GYaN
  • 2,327
  • 4
  • 19
  • 39
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
  • 502,043
  • 27
  • 286
  • 360
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
  • 722
  • 1
  • 4
  • 5
0
<?php
  $ddmmyyyy = date("d-m-Y", strtotime($data2['emp_dob']));
?>
MarcoS
  • 17,323
  • 24
  • 96
  • 174
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
  • 684
  • 1
  • 7
  • 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