Answer the question
In order to leave comments, you need to log in
PHP How to add two specific DateTime dates?
Welcome all!
I'm looking at DateTime examples, either I'm not looking well, or it's not there, but I can't find a solution for adding two specific time dates, for example: 10:55:00 + 05:35:00.
We have:
The first time value (Separately displayed via ECHO is excellent): $counttimeback->format("%H:%I:%S")
Second time value (Separately displayed via ECHO is excellent): $counttimethere->format("%H:%I:%S")
I am trying to summarize in this way:
$fulltime = $counttimeback->format("%H:%I:%S") + $counttimethere->format("%H:%I:%S");
//вывод
echo $fulltime->format("%H:%I:%S");
Answer the question
In order to leave comments, you need to log in
My solution that I needed:
$time = new DateTime('00:00:00');
$fulltime = clone $time;
$time->add($counttimethere);
$time->add($counttimeback);
echo 'Общее время:' . $fulltime->diff($time)->format("%H:%I:%S");
>Tell me how to sum two times
Algorithm:
1) Calculate the difference in seconds\minutes\years between time
2) Add the difference to the first time
3) ???
4) Profit!
$d1 = new \DateTime('2016-08-22 10:55:00');
$d1->add(new \DateInterval('PT5H35M'));
var_dump($d1);
And then there's Carbon. But this is the case when "just adding two dates" is not enough
carbon.nesbot.com/docs
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question