Reputation: 3823
I need to get just the day from a datetime value in php. I get from my database something like '2015-01-01 12:12:12' and I just need '2015-01-01' for adding after it ' 00:00:00' or ' 23:59:59'.
I tried:
echo $res0['dateInit'];
$date_day = date('yyyy-mm-dd',$res0['dateInit']);
$date_init = $date_day . " 00:00:00";
$date_end = $date_day . " 23:59:59";
echo $date_init;
echo "<br>";
echo $date_end;
But I get a wrong value in the second echo. What am I doing wrong?
Upvotes: 0
Views: 149
Reputation: 148
use strtotime, check the code given below:
$date = '2015-01-01 12:12:12';
$day = date('Y-m-d',strtotime($date));
$split_date = split(" ",$date);
print "day = $day and $date and $split_date[0]";
And the output is
day = 2015-01-01 and 2015-01-01 12:12:12 and 2015-01-01
Upvotes: 3