TRemmie Posted October 5, 2009 Share Posted October 5, 2009 I need help coding a PHP countdown script that will echo days remaining till the next upcoming first tuesday of the next month. I can find scripts that will display the next upcoming tuesday in the week but not the first of the month. Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted October 6, 2009 Share Posted October 6, 2009 this would be it roughly and I think you might have trouble if you're dealing with a non standard timestamps or timezone outside of the US time zones. $thistues=strtotime("first tuesday"); $today=strtotime(date("Y-m-d")); $nexttues=($today<$thistues)?$thistues:date("Y-m-d", strtotime("first tuesday", strtotime("+ 1 Month", strtotime(date("Y-m")))));; $seconds=($nexttues-$today); $minutes=($seconds/60); $hours=($minutes/60); $days=($hours/24); echo "There are ".$days." days left until next tuesday"; Quote Link to comment Share on other sites More sharing options...
TRemmie Posted October 6, 2009 Author Share Posted October 6, 2009 This is echoing back "There are 7 days left until next tuesday" but we are looking for "24 days remaining till the next first tuesday". $thistues=strtotime("first tuesday"); $today=strtotime(date("Y-m-d")); $nexttues=($today<$thistues)?$thistues:date("Y-m-d", strtotime("first tuesday", strtotime("+ 1 Month", strtotime(date("Y-m")))));; $seconds=($nexttues-$today); $minutes=($seconds/60); $hours=($minutes/60); $days=($hours/24); echo "There are ".$days." days left until next tuesday"; Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted October 6, 2009 Share Posted October 6, 2009 try this instead $thistues=strtotime("first tuesday",strtotime(date("Y-m"))); $today=strtotime(date("Y-m-d")); $nexttues=($today>=$thistues)?strtotime("first tuesday", strtotime("+ 1 Month", strtotime(date("Y-m")))):$thistues; $seconds=($nexttues-$today); $minutes=($seconds/60); $hours=($minutes/60); $days=($hours/24); echo "There are ".floor($days)." days left until next tuesday"; Quote Link to comment Share on other sites More sharing options...
TRemmie Posted October 6, 2009 Author Share Posted October 6, 2009 Thanks for the help, unfortunatly, its still echoing back 7 days. Quote Link to comment Share on other sites More sharing options...
sasa Posted October 6, 2009 Share Posted October 6, 2009 try <?php function days_to_next_tu(){ $day = date('t')-date('j'); $f = mktime(0,0,0,date('n')+1,1,date('y')); $d = date('w', $f); $t = $d > 2 ? 9-$d: 2-$d; return $day+$t+1; } echo days_to_next_tu(); ?> Quote Link to comment Share on other sites More sharing options...
TRemmie Posted October 6, 2009 Author Share Posted October 6, 2009 Think thats it Thank you so much for the help all. Quote Link to comment Share on other sites More sharing options...
salathe Posted October 6, 2009 Share Posted October 6, 2009 If you're up for using some of the really nice additions in PHP 5.3, then you could also use the following: <?php $now = new DateTime(); $tues = new DateTime('first tuesday of next month'); $diff = $now->diff($tues); echo $diff->days; ?> 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.