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

有帮助吗?

解决方案

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

其他提示

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);
?>

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top