0

I am getting the time with DialogFlow and the time format is something like "2020-08-28T14:00:00+02:00". I need to get the substraction between a time stored in the data base (format: "H:i:s" -> "12:01:00");

                    $time = $res2["Results"][0]["time"]; // the time of data base
                    $time_converted = DateTime::createFromFormat("H:i:s", $time);

                    $time_end_converted = strtotime("yyyy-MM-dd'T'HH:ii:ss", $params->time_end); //time from dialogflow
                    //var_dump($time_end_converted);
                    $interval = abs($time - $time_end_converted);
                    $time_end = date('H:i:s', $interval);
                    //var_dump($time_end);

But the difference between both times are not correct. I think the time_end_converted has not got a correct format. How can i convert the time from DialogFlow to a time with the format "H:i:s"??

Thanks!

Monetillo
  • 29
  • 5
  • I noticed that you are not using the timezone (+02:00) in the strtotime, the difference that you are not perceiving would not be these 2 hours of the timezone? – Rodrigo Teixeira Andreotti Aug 27 '20 at 16:40
  • Does this answer your question? [How do I compare two DateTime objects in PHP 5.2.8?](https://stackoverflow.com/questions/961074/how-do-i-compare-two-datetime-objects-in-php-5-2-8) – BadHorsie Aug 27 '20 at 16:51
  • @BadHorsie I tried to convert both in DateTime but an error happened. – Monetillo Aug 28 '20 at 14:28
  • @RodrigoTeixeiraAndreotti I am not sure, but I tried and I think that it only indicates the time zone – Monetillo Aug 28 '20 at 14:44

1 Answers1

0

At the end, I realised that the format is not needed to create DateTime so I finally do this:

$time = $res2["Results"][0]["time"];
$time_converted = DateTime::createFromFormat("H:i:s", $time);
$time_end_converted = new DateTime($params->time_end);
$interval = $time_converted->diff($time_end_converted); 
$time_end = $interval->format("%H:%I:%S"); 
              

Thank you everyone for helping me!

Monetillo
  • 29
  • 5