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. Link to comment https://forums.phpfreaks.com/topic/176625-solved-countdown-to-first-tuesday-of-every-month/ 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"; Link to comment https://forums.phpfreaks.com/topic/176625-solved-countdown-to-first-tuesday-of-every-month/#findComment-931173 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"; Link to comment https://forums.phpfreaks.com/topic/176625-solved-countdown-to-first-tuesday-of-every-month/#findComment-931630 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"; Link to comment https://forums.phpfreaks.com/topic/176625-solved-countdown-to-first-tuesday-of-every-month/#findComment-931646 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. Link to comment https://forums.phpfreaks.com/topic/176625-solved-countdown-to-first-tuesday-of-every-month/#findComment-931781 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(); ?> Link to comment https://forums.phpfreaks.com/topic/176625-solved-countdown-to-first-tuesday-of-every-month/#findComment-931845 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. Link to comment https://forums.phpfreaks.com/topic/176625-solved-countdown-to-first-tuesday-of-every-month/#findComment-931862 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; ?> Link to comment https://forums.phpfreaks.com/topic/176625-solved-countdown-to-first-tuesday-of-every-month/#findComment-931903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.