PHP Select every other Wednesday

前端 未结 4 1730
天命终不由人
天命终不由人 2021-01-27 01:18

I need help Select every other Wednesday starting on 5/2/12. This code below selects every other Wednesday starting on the week it currently is. But i need to set the beginning

4条回答
  •  孤街浪徒
    2021-01-27 02:20

    You could also use the DatePeriod and DateInterval classes to make life easier.

    Standard disclaimer: both of the classes above require PHP >= 5.3.0.

    $number_of_dates = 10;
    
    $start_date = new DateTime("5/2/12");
    $interval   = DateInterval::createFromDateString("second wednesday");
    $period     = new DatePeriod($start_date, $interval, $number_of_dates - 1);
    
    foreach ($period as $date) {
        echo $date->format("m-d-Y") . "
    " . PHP_EOL; }

提交回复
热议问题