View Full Version : php date help

10-09-2006, 02:20 PM

I need to store a download date in a MySQL Database when a user makes an order, and check to see if that download date has expired when the user logs in in the future. What would be the best way to do this? timestamp?

Is there a PHP function that can anaylze the timestamp (or some sort of date string) and check to see how much time is left?

Example: User orders download access for 24 hours - Comes back 5 hours, 20 minutes later - It should tell him that he has 18 hours fourty minutes left.

I just need help on the timestamp/php date/math function... I've got the database queries down.


10-09-2006, 03:22 PM
Hmm...you could try something like this.

//I am going to assume that the funtion getLast() returns the timestamp of
//when they ordered the item
$old = getLast();
$diff = time() - $old;
if($diff >= 86400){
//been longer than a day
$return = 'It has been to long';
$hours = date('H',$diff);
$minutes = date('i',$diff);
$return = 'You have $hours hours and $minutes minutes left';
echo $return;