Getting first weekday in a month with strtotime

前端 未结 6 1432
情深已故
情深已故 2020-12-03 21:52

I\'m trying to figure out the first wednesday of a given month using strtotime, but the \"first wednesday\" argument fails whenever the first wednesday happens

6条回答
  •  Happy的楠姐
    2020-12-03 22:32

    Building off the answers provided, one needs to be aware of differences in relative date formatting between php 5.2 and php 5.3.

    TEST:

    $date1 = strtotime("first wednesday of 2010-12");
    $date2 = strtotime("first wednesday 2010-12");
    $date3 = strtotime("wednesday 2010-12");
    

    5.2 Results:

    1969-12-31
    2010-12-08
    2010-12-01
    

    5.3 Results:

    2010-12-01
    2010-12-08
    2010-12-01
    

    Therefore only the third method returns correct results across PHP 5 versions.

提交回复
热议问题