Jump to content

[SOLVED] Countdown to first tuesday of every month.


TRemmie

Recommended Posts

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
Share on other sites

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".  :shrug::confused:

 

$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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.