0

i have a field in my model called creation_time whose type is datetime. so echo $model->creation_date;die(); will display a value like this

2015-10-07 09:55:17

i want to get only the date ie, 2015-10-07.How can i do that? i have tried something like this

$d = date('Y-m-d', $model->creation_date);
echo $d ; die();

but i got an error which says A non well formed numeric value encountered

then i tried like this

$s = $model->creation_date;
$dt = new DateTime($s);
$date = $dt->format('m/d/Y');echo $date; die();

now i get error like this 'app\controllers\DateTime' not found

Bloodhound
  • 2,836
  • 10
  • 33
  • 69

1 Answers1

8

Try like below and let me know.

$d = date('Y-m-d', strtotime($model->creation_date));
echo $d; die();
Kausha Mehta
  • 2,770
  • 1
  • 17
  • 31