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. Link to comment https://forums.phpfreaks.com/topic/75799-solved-expression-to-show-date-status/ Share on other sites More sharing options...
rajivgonsalves Posted November 2, 2007 Share Posted November 2, 2007 $expires is it in seconds, hours... etc.. Link to comment https://forums.phpfreaks.com/topic/75799-solved-expression-to-show-date-status/#findComment-383627 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? Link to comment https://forums.phpfreaks.com/topic/75799-solved-expression-to-show-date-status/#findComment-383634 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/ Link to comment https://forums.phpfreaks.com/topic/75799-solved-expression-to-show-date-status/#findComment-383692 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. Link to comment https://forums.phpfreaks.com/topic/75799-solved-expression-to-show-date-status/#findComment-383840 Share on other sites More sharing options...
hostfreak Posted November 3, 2007 Author Share Posted November 3, 2007 Anyone have any ideas? Thanks. Link to comment https://forums.phpfreaks.com/topic/75799-solved-expression-to-show-date-status/#findComment-384100 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'; } ?> Link to comment https://forums.phpfreaks.com/topic/75799-solved-expression-to-show-date-status/#findComment-384622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.