php - how to add 7 days to a formatted date -
i need able add 7 date formatted date.
i have variable:
$holiday has value of wednesday 1st of january (for example);
i tryng add 7 days result output 8th of january fails, code use follows
if (strpos($holiday,'1st') && strpos($holiday,'january') == true) {$result = date("l js \of f", strtotime( $holiday. "+ 7 day" ));}
no errors in php log
so if examples wednesday 1st of january
format.
like [day] [daynum] [of] [month]
then can do:
$date ='wednesday 1st of january'; $arr = explode(' ',$date); $arr[1]=(int)$arr[1];//we cast `1st` int becomes `1` unset($arr[2],$arr[0]);//we ignore `of` , `day` $datenew = implode(' ',$arr); $d = datetime::createfromformat('j f',$datenew); print $d->format('y-m-d');//2017-01-01 print $d->modify('+7 days')->format('y-m-d');//2017-01-08
Comments
Post a Comment