Re: date time problem

From: Date: Mon, 07 Oct 2013 14:07:09 +0000
Subject: Re: date time problem
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.general 
Request: Send a blank email to php-general+get-322261@lists.php.net to get a copy of this message
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';
}

« previous php.general (#322261) next »