I need to find the difference in days between two timestamps.
$now = date("Y-m-d");
//This return 2017-01-04
$last_active = date("Y-m-d", strtotime($user->updated_at->toDateTimeString()));
//This returns for example: 2016-07-20
$datediff = $now - $last_active;
$days = floor($datediff/(60*60*24));
This code keeps returning 0 for $days.
However it seems that the $now
and $last_active
works as strings, and thereby i cant just substract the two from eachother, and then $days will simply return 0.
How do I substract the two from eachother? I need someway to parse them into some sort of variable, where I can substract the two.
So far ive tried the following:
Finding the number of days between two dates This does not work, because my variables are as strings, is my guess.
Also I have tried parsing the dates into integers, but this would result in, for example 20170104 - 20160720 which gives a value that has nothing to do with the difference in days from the two.
Hoping for some helpful pointers
Best Regards, Patrick