php - adding one day to a custom formatted date string -


i have string in format yyyymmddhh24miss year, month, day, hours, minutes, seconds. want convert date, add 1 day , return in same format. sounds simple unable work. have tried number of different ways $field3 contains date string example:

                $end_date = strtotime(substr($field3,1,8));                 $date_interval = dateinterval::createfromdatestring('1 day');                 $new_end_date = date_add($end_date, $date_interval);                 $field3 = ($new_end_date->format('yyyymmdd')).substr($field3,8,6); 

in example $new_end_date contains "false".

example date time string: 20170912124159 being 12/09/2017 12:41:59

the format of input string can parsed constructor of class datetime (and date_create() , strtotime()) without problems.

$date = new datetime('20170912124159'); $date->add(new dateinterval('p1d')); echo($date->format('y-m-d h:i:s'));  # output is: # 2017-09-13 12:41:59 

you can, well, format date string using format ymdhis modified date in same format input string.

echo($date->format('ymdhis')); # 20170913124159 

read datetime , dateinterval.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -