Year and week to date in php

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

    function getStartAndEndDate($week, $year) 
    {
        //setting the default time zone
        date_default_timezone_set('America/New_York');
    
        //getting the
        //$firstWeek = date('W',strtotime("January 1 $year", date(time())));
        //echo "Year : ".$year."
    "."Week : ".$week."
    "; $firstWeekThursDay = date('W',strtotime("January $year first thursday",date(time()))); if($firstWeekThursDay == "01") { $time = strtotime("January $year first thursday",date(time())); //echo $time."
    "; //echo date('Y-m-d H:i:s',$time)."
    "; $time = ($time-(4*24*3600))+(((7*$week)-6)*24*3600); //echo $time."
    "; //echo date('Y-m-d H:i:s',$time)."
    "; $return[0] = date('Y-m-d', $time); $time += 6*24*3600; $return[1] = date('Y-m-d', $time); //print_r($return); } else { $time = strtotime("January 1 $year", time()); //echo "
    ".$time."
    "; //echo date('Y-m-d H:i:s',$time)."
    "; $time = ($time-(4*24*3600))+(((7*$week)-6)*24*3600); //echo $time."
    "; //echo date('Y-m-d H:i:s',$time)."
    "; $return[0] = date('Y-m-d', $time); $time += 6*24*3600; $return[1] = date('Y-m-d', $time); //print_r($return); //echo "
    End of Hi
    "; } return $return; }

提交回复
热议问题