shadiadiph Posted January 17, 2009 Share Posted January 17, 2009 in my coding i want to display certain things in different colors for example $expiry is a date value in the database $status is just a css class i want to make it if $expiry == less than 7 days from the date value of expiry??? I have no clue i am just guessing ;( if ($expiry == "> 7%d '$expiry'") { $status="status7days"; } Quote Link to comment Share on other sites More sharing options...
btherl Posted January 17, 2009 Share Posted January 17, 2009 You can fetch the expiry value from the database and then compare it. Or you can ask the database to compare it for you. Are you already fetching the expiry value from the database? If so, please show the code. How to do the comparison depends on what format the date is in. Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted January 17, 2009 Author Share Posted January 17, 2009 expiry is being called from the database to display so it is as $expiry = $row["expiry"]; Quote Link to comment Share on other sites More sharing options...
ratcateme Posted January 17, 2009 Share Posted January 17, 2009 $expiry_ts = strtotime($expiry); if($expiry_ts < strtotime("-7 days",$expiry_ts)){ $status="status7days"; } should do it you might need to change the < to a > haven't thought it through properly Scott. Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted January 17, 2009 Author Share Posted January 17, 2009 mm that doesn't work but thanks for trying Quote Link to comment Share on other sites More sharing options...
ratcateme Posted January 17, 2009 Share Posted January 17, 2009 sorry i am a little confused and that script will never work $expiry == less than 7 days from the date value of expiry doesn't really make sense to me should it be that: if (current time - 7 days ) < $expiry?? Scott. Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted January 17, 2009 Author Share Posted January 17, 2009 mm one thing i failed to mention is that $expiry has more than one value in the database but when i call $print expiry; it displays 2009-01-20 this didn't work either and $expiry == less than 7 days from the date value of expiry was not code just an expample of what i am trying to acheive. if (current time - 7 days ) < $expiry { $status="status7days"; } when i just tried this $expiry_ts = strtotime($expiry); print $expiry_ts; it displayed this 1232384400 Quote Link to comment Share on other sites More sharing options...
ratcateme Posted January 17, 2009 Share Posted January 17, 2009 sorry i didn't mean to say it was invalid code i just can't make sense of what you are saying to m it reads expiry needs to be less than 7 days from the value of expiry which to me is impossible because the way i read it was that there was only one expiry. so if you have two expires one from the database and one from somewhere else try $expirya_ts = strtotime($expiry_from_db); $expiryb_ts = strtotime($expiry_from_somewhere); if($expirya_ts < strtotime("-7 days",$expiryb_ts)){ $status="status7days"; } i think?? Scott. Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted January 17, 2009 Author Share Posted January 17, 2009 nothing seems to work i am going to forget about it thanks for trying though 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.