Determining the number of days between to UNIX timestamps

So I needed to know how many days there were between to UNIX timestamp values, and here is the code for those who may also need it.

function dateDiffUnix($startDate) {

echo ‘$start_date ‘.$startDate.’ – ‘.date(‘Y m d G:i:s’, $startDate).'<br />’;
$endDate = time();
echo ‘$end_date ‘.$endDate.’ – ‘.date(‘Y m d G:i:s’, $endDate).'<br />’;
$difference = $endDate – $startDate;
return round($difference / 86400);
echo ‘Unix date difference: ‘.dateDiffUnix(“1292479971”);        // start time
In my case the start date will be passed in as a value from the database, but for this sample, a hard-coded value will suffice.




Leave a Reply

Your email address will not be published. Required fields are marked *