PHP Select every other Wednesday

前端 未结 4 1883
天命终不由人
天命终不由人 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:14

    Use mktime to create your starting date and pass that as the second argument to strtotime so that counting starts from there:

    $startDate = mktime(0, 0, 0, 5, 2, 2012); // May 2, 2012
    for ($i = 0; $i < $number_of_dates; $i++) {
       $date = strtotime('Wednesday +' . ($i * 2) . ' weeks', $startDate);
       echo date('m-d-Y', $date). "
    ".PHP_EOL; }

    See it in action.

提交回复
热议问题