Adding minutes to time in PHP -


i'm trying add 60 or 90 minutes given time using php.

i've tried doing in 2 ways, both ending unexpected result.

input data:

$data['massage_hour_from'] = '09:00:00'; $data['massage_duration'] = 60; 

first try:

$data['massage_hour_to'] = date('h:i:s', strtotime('+' . $data['massage_duration'] . ' minutes', strtotime($data['massage_hour_from']))); 

second try:

$datetime = new datetime($data['massage_date']); $datetime->settime($data['massage_hour_from']); $datetime->modify('+' . $data['massage_duration'] .' minutes'); $data['massage_hour_to'] = $datetime->format('g:i:s'); 

what doing wrong?

i replaced variable names shorter ones, code works:

$from = '09:00:00'; //starting string $duration = 90; //in minutes $date = new datetime($from); $date->add(new dateinterval("pt{$duration}m"));//add minutes $to = $date->format('h:i:s'); // '10:30:00' 

live demo


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -