Find week days date from range of the two dates

前端 未结 9 1827
执念已碎
执念已碎 2020-12-24 09:03
$start_date = "2013-05-01";
$last_date = "2013-08-30";

How can I get dates of tuesdays and thursdays between these two dates?

9条回答
  •  误落风尘
    2020-12-24 10:06

    format("N") == 2 || $dt->format("N") == 4) {
            echo $dt->format("l Y-m-d") . "
    \n"; } }

    See it in action

    What this code does:

    1. Creates a starting date object using DateTime.
    2. Creates a starting date object using DateTime.
    3. Creates a DateInterval object to represent our interval of time to iterate through. In this case 1 day.
    4. Creates a DatePeriod object to manage these objects.
    5. Using DatePeriod, it iterates through the date starting with the starting date and ending at the end date. We use DateTime::format() with the N parameter to get the day number of the week. If the day number of the week is 2 (Tuesday) or 4 (Thursday) echo out it's value.

提交回复
热议问题