-2

I am getting value of DOB field and its object of array from DB like this.

echo $value->dob;

got output like this 1989-10-04 00:00:00.000000

I want to display value like 04-10-1989 only.

Please help me out

  • You can use the PHP methods of [strtotime](http://us1.php.net/manual/en/function.strtotime.php) and [date](http://us1.php.net/manual/en/function.date.php), or you can use the mysql method of [DATE_FORMAT()](https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format) – aynber Feb 23 '18 at 18:22
  • This can be solved in different ways, what did you try so far? This might help us to give out the answer that best fits your needs... – holden Feb 23 '18 at 18:35
  • Possible duplicate of [Convert one date format into another in PHP](https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Paul Karam Feb 23 '18 at 18:50
  • Thanks @aynber I fixed it just because of you. I got frustrated while doing this. – Prem Kishore Gupta Feb 23 '18 at 19:24

2 Answers2

0

Try this example

$dob = '1989-10-04 00:00:00.000000';

$new_dob = date('d-m-Y', strtotime($dob));

echo $new_dob;

produces

04-10-1989
0

Do like this $dob = 'your database date value';

$dob1= date('d-m-Y', strtotime($dob));

echo $dob1;

Anil Kumar Sahu
  • 567
  • 2
  • 7
  • 27