PHP - get last week number in year

后端 未结 6 2102
Happy的楠姐
Happy的楠姐 2020-12-01 16:08

Tell me please how to get the last number of weeks in a year?

6条回答
  •  Happy的楠姐
    2020-12-01 16:20

    In ISO-8601 specification, it says that December 28th is always in the last week of its year.
    Based on that, we can simply create that date, and see in what week it is:

    $dt = new DateTime('December 28th');
    echo $dt->format('W'); # 52
    
    $dt = new DateTime('December 28th, 2009');
    echo $dt->format('W'); # 53
    

    demo

    ... or if you are using date() and strtotime() functions: echo date('W', strtotime('December 28th')); # 52

提交回复
热议问题