centenial Posted October 9, 2006 Share Posted October 9, 2006 Hi,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.Thanks! Quote Link to comment Share on other sites More sharing options...
miseleigh Posted October 9, 2006 Share Posted October 9, 2006 Try php's time() function, it'll give you a timestamp - you can store this in your db for the order time. Then when they come back, it's just a calculation and formatting:$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. Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 9, 2006 Share Posted October 9, 2006 i would suggest storing any times or dates in mysql using date, time or datetime datatypes. you can then easily transfer it to a UNIX timestamp for calculations using strtotime(). miseleigh has given you a really good starting point for your calculations. there are a couple ways that may be a little more friendly for what you're after, but it's definitely a good jumping off point for you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.