the value in variables is "13 minutes 34 seconds", "14 seconds", "5 minutes 26 seconds"

how do i count the total amount of time php javascript

  • may still be HOUR "18 hours 33 minutes 27 seconds" - Shked Asket
  • one
    Can with the help of regulars, parsit the number before the word and accordingly take appropriate action - entithat

2 answers 2

$DATE_1 = new DateTime('NOW'); $DATE_2 = clone $DATE_1; $ARRAY = [ "13 minutes 34 seconds", "12 seconds", "5 minutes 26 seconds" ]; foreach ($ARRAY as $value) { $DATE_2->modify($value); } $DIFF = date_diff($DATE_1, $DATE_2); var_dump($DIFF); 

$DIFF work with $DIFF .

  • it seems to me that you gave the wrong answer, sorry, but I know very little php - Shked Asket
  • object (DateInterval) # 5 (8) {["y"] => int (0) ["m"] => int (0) ["d"] => int (0) ["h"] => int (0) ["i"] => int (19) ["s"] => int (12) ["invert"] => int (0) ["days"] => int (0)} - Shked Ascetic
  • @ ShkedAsket Well? Have you got DateInterval with English chtol too bad? php.net/manual/ru/class.dateinterval.php - documentation. If you need the total number of seconds, then: var_dump($DIFF) change to: var_dump($DATE_2->getTimestamp() - $DATE_1->getTimestamp()) - Manitikyl
  • thank you very much for the answer! and excuse me for disturbing - Shked Asket

Google gives this answer

time = 06: 58: 00, time2 = 00: 40: 00, result = 07:38:00

 $time = "06:58:00"; $time2 = "00:40:00"; $secs = strtotime($time2)-strtotime("00:00:00"); $result = date("H:i:s",strtotime($time)+$secs); 
  • How to change the time format then)? - Shked Ascetic