Year and week to date in php

前端 未结 4 846
孤独总比滥情好
孤独总比滥情好 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:00

    Try this out:

    $year = 2000;
    $week = 1;
    $start = date("l, M jS, Y", strtotime("01 Jan ".$year." 00:00:00 GMT + ".$week." weeks"));
    $end = date("l, M jS, Y", strtotime($start." + 1 week"));
    echo $start." to ".$end;
    

    You need to set $year and $week. It will then print the interval as specified.

    For instance, the output as-is is:

    Friday, Jan 7th, 2000 to Friday, Jan 14th, 2000
    

    Note that weeks are indexed from 0-51 (easy to fix).

    It's kind of ugly, but it works. Hope that helps!

提交回复
热议问题