php - Issues with Dates -


i have need range mon-sun each week, beginning current.

this came with:

$range = 0; $weeknumber =  date("w", strtotime(date('l j  f y') . '  ' . ($range) . ' days')); $weekyear =  date("y", strtotime(date('l j  f y') . '  ' . ($range) . ' days'));  $week_array = getweekdates($weeknumber, $weekyear);  function getweekdates($week, $year) {     $dto = new datetime();     $ret['mon'] = $dto->setisodate($year, $week)->format('y-m-d');     $ret['tue'] = $dto->modify('+1 days')->format('y-m-d');     $ret['wed'] = $dto->modify('+1 days')->format('y-m-d');     $ret['thu'] = $dto->modify('+1 days')->format('y-m-d');     $ret['fri'] = $dto->modify('+1 days')->format('y-m-d');     $ret['sat'] = $dto->modify('+1 days')->format('y-m-d');     $ret['sun'] = $dto->modify('+1 days')->format('y-m-d');     return $ret; } 

it works on local wampserver (5.3.4), when try t run on godaddy (5.2.17), getting error:

fatal error: call member function format() on non-object in /home/.....php on line ($ret['mon'] = $dto->setisodate($year, $week)->format('y-m-d');)

according the documentation, return value "setisodate" , "modify" changed null datetime starting in 5.3. why works in newer php environment not older one.

to make code compatible, change code this:

$dto->setisodate($year, $week); $ret['mon'] = $dto->format('y-m-d'); $dto->modify('+1 days'); $ret['tue'] = $dto->format('y-m-d'); //so forth rest of days 

here way write function:

function getweekdates($week, $year) {     $dto = new datetime();     $dto->setisodate($year, $week);     $keys = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');     $ret = array();     for($i = 0; $i < 7; $i++) {         $ret[$keys[$i]] = $dto->format('y-m-d');         $dto->modify('+1 days');     }     return $ret; } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -