Handling Dates in PHP
Posted 09 October 2006 - 02:19 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.
Posted 09 October 2006 - 03:37 PM
$time_left = time() - $order_time;
echo strftime("You have %j days, %H hours, and %M minutes left", $time_left);
There are a few things to be aware of with this script. The %j option is the day of the year by decimal # (for example, Feb 2nd would be the 33rd day) so it will only go as high as 366. There are more options listed to include years if you need them - check the manual. Also, if the user orders access for a day and it crosses daylights savings time, they'll still get exactly 24 hours even though that particular day might have either 25 or 23 hours in it.
Posted 09 October 2006 - 04:23 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users