View Single Post
Old 12-13-2007, 07:05 PM   #4 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
Salathe is on a distinguished road
Default

As an aside, you don't need to do date('z', strtotime(date('Y-m-d H:i'))) to get today's day of the year. Simply skip the second argument to use the current time stamp: date('z').

Personally, I'd prefer working with the timestamps themselves and only use the date() function for outputting friendly strings. Something like the the following:
php Code:
<?php

$iDateStart   = 1195958278;

// expiry = starting timestamp + 90 days (in seconds)
$iDateExpire  = $iDateStart + (90 * 24 * 60 * 60);

// Days left = difference between timestamps in seconds (expiry - now)
//             divided by number of seconds in a day (86,400)
// Use floor() to round down to the day.
$iDaysLeft    = floor(($iDateExpire - time()) / (24 * 60 * 60));

// Output:
// There are 71 days left until 2008-02-23 02:37.
printf('There are %d days left until %s.',
       $iDaysLeft,
       date('Y-m-d H:i', $iDateExpire));
Salathe is offline  
Reply With Quote