Reputation: 35
I want to extract date without time from a single value from array result thaht I got.
I tried using array_slice but it didn't work.
My code..
$dateRows = $this->get('app')->getDates();
$dateRow = json_decode(json_encode($dateRows[0], true));
dump($dateRow[0]);die;
And I got result..
"2014-01-01 00:00:00"
And I want it to return just
"2014-01-01"
Upvotes: 0
Views: 70
Reputation: 155
you can use strtotime function as well for getting formatted data
$a = "2014-01-01 00:00:00";
echo date('Y-m-d', strtotime($a));
Upvotes: 0
Reputation: 3809
Very Simple, just use date_create()
on your date & then format it using date_format()
as follows -
$date = date_create("2014-01-01 00:00:00");
echo date_format($date,"Y-m-d");
So, in your case, it would be something like -
$date1 = date_create($dateRows[0]);
echo date_format($date1,"Y-m-d");
Upvotes: 2