如果我已经知道这个日期的日期,如何找出下一个日期?

How to find out next date if i have already knows day of this date?

假设,我有三个变量。

$curr_day = "monday";
$curr_date = "12/12/2222";//('d/m/y')
$next_day = "friday";

$next_date = ??;

下一个日期是什么时候? 有什么 "php functions" 可以帮助我找到 $next_date 吗?

提前致谢。

你试过了吗:

var_dump(new DateTime('next friday'));

我通常使用DateTime来解决日期相关的问题。看看下面的例子:

// Make a new DateTime object using your date
$date = DateTime::createFromFormat('Y-m-d', '2016-05-25');

// Modify the object to get the next date
$date->modify('next friday');

// Output the date
echo $date->format('Y-m-d');

你只需要:

var_dump(new DateTime('2016-05-29 next friday'));

“2016-05-29”后下周五给大家。

object(DateTime)[2]
  public 'date' => string '2016-06-03 00:00:00.000000' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Berlin' (length=13)

您已完成具有所需功能的示例:

$curr_day = "monday";
$curr_date = "26/05/2016";
$date = DateTime::createFromFormat('d/m/Y', $curr_date);
$nextDate = new DateTime($date->format('Y-m-d').' next friday');
var_dump($nextDate->format("d/m/Y"));

string '27/05/2016' (length=10)

我假设您的 $curr_datem/d/Y 格式 (如果不是,请澄清您的问题,因为 12/12 令人困惑)

您可以使用 strtotime 作为计算相对日期的简单方法。参见 Example #1

$curr_day = "Monday";
$curr_date = "12/12/2222";
$next_day = "Friday";

// Convert your string $curr_date to timestamp
$curr_date = strtotime( $curr_date );

// Then use again strtotime to calculate the relative date.
echo date('m-d-Y', strtotime( "next " . $next_day, strtotime( $curr_date ) ) );

希望对您有所帮助!

PS:顺便说一句,12/12/2222 不是星期一,而是 Thursday

试试吧!这...

// get next date
$d = new DateTime($curr_date);
$next_date = new DateTime($d->format('d/m/y'));
echo $next_date->modify('+1 day'); //13/12/2222