Get date of this week thursday OR next week thursd

2019-08-17 16:47发布

问题:

I need to get the DATE of this week's Thursday (or any other day) OR next week's Thursday (or any other day)

The scenario is that there are 3 tours happening every week.. I need to find out next tour date

If today is tuesday and date is 21/01/2014 and tours happen on tuesday, friday and sunday.. then I need to find out next tour date which will be on friday on friday

Similarly, if today is Friday, I'll need to find out date on next week's tuesday.

So far, I tried using strtotime("next tuesday") but it doesn't seem to work well

回答1:

echo strtotime("next Thursday");

Example straight from PHP.net, should work. And for the Thursday after that one you can do

$nextThursday= strtotime("next Thursday");
$secondThursday=strtotime("next Thursday",$nextThursday); // And so on

Demo



回答2:

Try this,

<?php
$next_thursday    =     strtotime("next Thursday");
$this_thurday     =     strtotime('thursday this week');
if($next_thursday==$this_thurday)
{ 
$numberOfWeeks = 1;
$next_thursday = $next_thursday + ($numberOfWeeks * 60 * 60 * 24 * 7);
}
echo date("Y/m/d", $this_thurday);
echo date("Y/m/d", $next_thursday);
?>


回答3:

I was looking for something like this and found the following in a comment here from deceze:

(new DateTime('now'))->modify('+5 days')

I used this in the follow way:

$date = DateTime('15 apr 15');
$date->modify('next thursday');
var_dump($date);

This worked for me so I am putting this out there as another possibility for those looking.



回答4:

Its working........
echo strtotime("next Thursday"), "\n";
Click here for detail: http://us.php.net/strtotime