How to get the date of every monday in a month for a given year

前端 未结 1 470
无人共我
无人共我 2021-01-25 10:19

I\'m trying to get the date of every Monday in a month. I previously did this for every first Monday and it worked.

$date = strtotime(\"second monday of $month[$         


        
相关标签:
1条回答
  • Why don't you get first monday, and do a loop adding 7 days to it until it is next year?

    $first = strtotime("first monday of $year[$j]");
    $lastday = mktime(0, 0, 0, 12, 31, $year[$j]);
    
    $day = $first;
    do {
        echo date('M d, Y', $day);
        $day += 7 * 86400;
    
    } while ($day < $lastday);
    
    0 讨论(0)
提交回复
热议问题