Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get date string only from an array containing a datetime string [duplicate]

I want to get only the date from an array containing a datetime string.

Array is:

print_r($incomplete);
Output:
Array
(
    [0] => 2015-09-21 11:20:37
)

And I want in below Format,

Array
(
    [0] => 2015-09-21
)

I have tried like this,

echo date('Y-m-d',strtotime($incomplete));
like image 977
Viral Bhoot Avatar asked Mar 09 '26 15:03

Viral Bhoot


1 Answers

The date conversion code works. What you have in $incomplete is an array, so you will have to use $incomplete[0] to access that value. Easy solution for that would be this:

$incomplete[0] = date('Y-m-d',strtotime($incomplete[0]));

Now you have the same array data without the time.

like image 128
Andrius Avatar answered Mar 12 '26 06:03

Andrius