brissy_matty Posted August 1, 2007 Share Posted August 1, 2007 Hi All, Getting stuck on a bit of a date problem. I want to display "ACTIVE" if the startdate is the current date or greater then the current date BUT less then or equal to the enddate. Basically to show if an item is active or not within a current date range. $startdate & $enddate both come from a date column in a mysql database. Below is what i thought would have worked... Apparently not.. Any ideas appreciated <?php $startdate=mysql_result($result,$i,"startdate"); $enddate=mysql_result($result,$i,"enddate"); $current=date("Y-m-d"); if ($current <= "$startdate" && $current >= "$enddate") { $status="<font color='green' face='verdana' size='1'>ACTIVE</font>"; } else { $status="<font color='red' face='verdana' size='1'>INACTIVE</font>"; } ?> Thanks Heaps Matt Quote Link to comment https://forums.phpfreaks.com/topic/62939-solved-date-question/ Share on other sites More sharing options...
akitchin Posted August 1, 2007 Share Posted August 1, 2007 you COULD simply use MySQL to its advantage here and add it as part of your SELECT query: SELECT stuff, (CASE NOW() WHEN BETWEEN startdate AND enddate THEN 'ACTIVE' ELSE 'INACTIVE' END) AS status FROM table have a look in the MySQL manual at the functions and operators section, you'll find a plethora of handy things. Quote Link to comment https://forums.phpfreaks.com/topic/62939-solved-date-question/#findComment-313385 Share on other sites More sharing options...
brissy_matty Posted August 2, 2007 Author Share Posted August 2, 2007 Thanks for pointing me in the right direction this is a much better solution i wasnt aware you could actually do something like that. Much appreciated. Matt Quote Link to comment https://forums.phpfreaks.com/topic/62939-solved-date-question/#findComment-313849 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.