hostfreak Posted November 2, 2007 Share Posted November 2, 2007 Hey, I'm storing a date in a database. The date will represent when something expires. I can show when it's expired or current, but I am unsure how to give a notice when it will be expiring within x days up until expiring. Here is what I have: <?php //Dates $current = date('Y-m-d'); $expires = '2007-11-07'; $notice = date('Y-m-d', mktime($expires) - 5 * 24 * 60 * 60); //try an interval of 5 days //Date Status if ($current >= $expires) { echo 'Expired'; } else if () //this is where I am unsure { echo 'Expiring within x days'; } else { echo 'Current'; } ?> By the way, I know I can do this via mysql, but want to know they way via php. Thanks in advanced. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 2, 2007 Share Posted November 2, 2007 $expires is it in seconds, hours... etc.. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted November 2, 2007 Author Share Posted November 2, 2007 $expires contains the date (Y-m-d) that it will expire. If that is what you were asking? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 2, 2007 Share Posted November 2, 2007 maybe this is what you wants http://www.ilovejackdaniels.com/php/php-datediff-function/ Quote Link to comment Share on other sites More sharing options...
hostfreak Posted November 2, 2007 Author Share Posted November 2, 2007 I don't quite think that is what I want. I don't need it to list exactly how many days until the expired date, just inform them if it is within x days of expiring. Although, that could be nice. However for the sake of simplicity, just show within the x days. So say within 32 days; it could be 32 or even 10, but it would still say "Within 32 days". Unless of course it is expired or current. Thanks for the responses so far. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted November 3, 2007 Author Share Posted November 3, 2007 Anyone have any ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted November 4, 2007 Author Share Posted November 4, 2007 Just for anyone curious, I have figured out a solution. Was easier than I thought; was just a matter of not being so lazy. Here is the solution: <?php //Dates $current = date('m-d-Y'); $expires = '2007-11-09'; //Date that the " " expires. Can be an expiration of anything. Can also be pulled from a database. Must be in Y M D formatt, unless you want to edit the code list($year, $month, $day) = explode('-', $expires); $notice = date('m-d-Y', mktime(0, 0, 0, $month, $day, $year) - (5 * 24 * 60 * 60)); //Subtract x amount of days (5 in this case) from the expiring date to start the expiring notice. //Date Status if ($current >= $expires) { echo 'Expired'; } else if ($current >= $notice && $current <= $expires) { echo 'Expiring within 5 days'; } else { echo 'Current'; } ?> 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.