Get difference between two dates in days
Hi there
Got the example from here: http://runnable.com/Umo8HFk2lxM6AAE6/get-the-difference-between-two-dates-with-date_diff-function-for-php
But I want to share my own example as well.
$kickoff_date = '2014/06/12';
$kickoff_date = date_create($kickoff_date);
$now = date_create(date('Y-m-d', time()));
$remaining = date_diff($kickoff_date, $now);
Var_dump'ing this $remaining object would give you the following output:
object(DateInterval)[475]
public 'y' => int 0
public 'm' => int 4
public 'd' => int 7
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'invert' => int 1
public 'days' => int 127
From here you can construct your output to suit your needs:
echo $remaining->m .' months and '. $remaining->d .' days left';
or
echo $remaining->days .' days left';
Written by Anriëtte
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#