简体   繁体   中英

How to get the date from year, month, week of the month, and day of the week in php

I have the year, month, week of the month and day of the week. I want to get a date. For example:

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

You can try to use PHP Relative Formats .

Something like this

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

It needs a little bit of conversion from numbers to strings but it's useful when you need to handle relative dates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM