Re: date time problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/6/2013 11:21 PM, Romain CIACCAFAVA wrote:
An easier way to do that would be using the diff() method of a DateTime object on another.

Regards
Romain Ciaccafava

Romain - you were so right. A little less calculating to be done and I got the result I wished. For anyone interested here's the function I'm using to determine how much time there is until a cookie expires. The cookie in question contains the expiration datetime that was used to create a paired cookie.

function GetTimeLeft($applid)
{
   if (isset($_COOKIE[$applid]))
   {
      if (isset($_COOKIE[$applid."expire"]))
      {
         $curr_time = new datetime();
         $cookietime = $_COOKIE[$applid."expire"];
         $exp_time = new datetime();
         $exp_time->setTimeStamp($cookietime);
         $diff = $curr_time->diff($exp_time);
         $days = $diff->format("%d");
         $days = ($days > 1) ? "$days days": ($days == 1) ?
               "$days day" : '';
         $hms = $diff->format("%h:%i:%s");
         return "Time left: $days $hms";
      }
      else
         return '?';
   }
   else
      return '0';
}



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux