jay0316 Posted December 30, 2009 Share Posted December 30, 2009 The following code checks the year the detail sheet was last completed against the current year. The idea was that each January it would show the user they need to complete another one. //Check Detail Date //grab year from stored date $Detail_Sheet = substr($Detail_Sheet, 0, stripos($Detail_Sheet, "-") ); //Check it against current year $y = date(Y); if ($Detail_Sheet == $y) { $d_class = "complete"; $d_icon = "images/complete.png"; } else { $d_class = "notcomplete"; $d_icon = "images/notcomplete.png"; } Now, we are allowing them 2 weeks into the new year to complete the previous year's sheet. Is there an easy way that I could modify this to still be dynamic and give them until Jan 14th each year to complete the previous year's sheet? I hope that makes sense. Thanks! Quote Link to comment Share on other sites More sharing options...
jonsjava Posted December 30, 2009 Share Posted December 30, 2009 <?php //Check Detail Date //grab year from stored date $Detail_Sheet = substr($Detail_Sheet, 0, stripos($Detail_Sheet, "-") ); //Check it against current year $y = date(Y); $d = date(z); if ($Detail_Sheet == $y || ($Detail_Sheet+1 == $y && $d < 14)) { $d_class = "complete"; $d_icon = "images/complete.png"; } else { $d_class = "notcomplete"; $d_icon = "images/notcomplete.png"; } This just checks to see if it's less than 14 days into the year. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 30, 2009 Share Posted December 30, 2009 Here's simpler solution. Just change the following line in your original script $y = date(Y, strtotime("-14 day")); On the first 14 days of the year $y will still be set to last year's value. If it will be possible for people to fill out the form for the current year during the first two weeks of the yesr, then change the comparison from == to >= Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 30, 2009 Share Posted December 30, 2009 Ok, here's a more compact version: //Check Detail Date //grab year from stored date $Detail_Sheet = substr($Detail_Sheet, 0, stripos($Detail_Sheet, "-") ); //Check it against current year $d_class = ($Detail_Sheet >= date(Y, strtotime("-14 day"))) ? 'complete': 'notcomplete'; Creating the variable $d_icon is a waste. Just use the variable $d_class when you need the icon. echo "<img src=\"images/{$d_class}.png\">"; Quote Link to comment Share on other sites More sharing options...
jay0316 Posted December 30, 2009 Author Share Posted December 30, 2009 mjdamato Thanks for that solution! Should -14 say "day" after or "days"? I saw on php.net someone used "days". Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 30, 2009 Share Posted December 30, 2009 Both 'day' and 'days' work for me. 'days' would probably read better to someone looking at the code. 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.