Year and week to date in php

前端 未结 4 847
孤独总比滥情好
孤独总比滥情好 2020-12-15 06:24

I have two pieces of information extracted from a MySQL database, the year(2009, 2010, ect) and the week (1-52). And I need to convert it i

4条回答
  •  无人及你
    2020-12-15 07:03

    $year = "2010"; // Year 2010
    $week = "01"; // Week 1
    
    $date1 = date( "l, M jS, Y", strtotime($year."W".$week."1") ); // First day of week
    $date2 = date( "l, M jS, Y", strtotime($year."W".$week."7") ); // Last day of week
    echo $date1 . " - " . $date2;
    

    If week number is under 10 then append a 0 before number. 1 won't work, it should be 01.

提交回复
热议问题