Get date of this week thursday OR next week thursday in php

一世执手 提交于 2019-12-11 19:07:55

问题


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


来源:https://stackoverflow.com/questions/21250346/get-date-of-this-week-thursday-or-next-week-thursday-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!