如何从PHP中的年,月,月中的星期几和星期几中获取日期

时间:2019-08-10 19:07:25

标签: php date weekday

我有年,月,日和星期几。我想约会 例如:

$year = 2019;
$month = 8;
$week = 2; // second week of the month
$day = 2; // tuesday
$date = getDate($year, $month, $week, $day); // $date = '06/08/2019'

1 个答案:

答案 0 :(得分:0)

您可以尝试使用PHP Relative Formats

类似这样的东西

$date = new DateTime('first day of August 2019');
$date->modify('tuesday next week');
echo $date->format('Y-m-d');

它需要一点点从数字到字符串的转换,但是在需要处理相对日期时很有用。