php add method incorrectly working -
i'm in process of learning php , i'm having trouble. function returning "milestones" same date plugged in with. believe using add() method incorrectly. thankyou.
phpplayground: http://www.tehplayground.com/#carb1wjth
$milestones = null; $milestones = createmilestone($milestones, true, 10, "15-1-1", "birthday" ); var_dump( $milestones ); function createmilestone($milestones, $forward, $days, $startdate, $milestonename ){ if ( is_string($startdate)){ $date = datetime::createfromformat("y-m-d", $startdate ); }else if(is_array($startdate) ){ $date = $startdate["date"]; }else{ $date = $startdate; }; $daysinterval = dateinterval::createfromdatestring($days); if ($forward){ $date->add($daysinterval); }else{ $date->sub($daysinterval); } $milestones[$milestonename]['date'] = $date; return $milestones; }
you need use :
$daysinterval = dateinterval::createfromdatestring($days . ' days');
see doc here dateinterval , page diverse date formatting (called relative format) can use.
and btw, if give datetime "15-1-1"
, correct format not "y-m-d"
"y-m-d
" (lowercase 'y
')
Comments
Post a Comment