iLite’s Weblog

January 5, 2011

Determining the number of days between to UNIX timestamps

Filed under: PHP — ilite @ 11:37 am

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.

 

 

 

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.