-7

Ihave two variable format time

example :

$start = 16:00:00
$end   = 20:00:00

expected results  = 04:00

how to find the difference

Ken Lee
  • 6,985
  • 3
  • 10
  • 29
  • Does this answer your question? [How to get time difference in minutes in PHP](https://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php) – juliomalves Jun 22 '21 at 23:30

2 Answers2

0

Try this

<?php
    $dteStart = new DateTime("16:00:00");
    $dteEnd   = new DateTime("20:00:00");
    $dteDiff  = $dteStart->diff($dteEnd);
    print $dteDiff->format("%H:%I"); // if you want to print seconds then use this: "%H:%I:%S" in format function
?>
Maxx P
  • 148
  • 10
0

Very Simple Solution :

$start = '16:00:00';
$end   = '20:00:00';

$start = date("g:i", strtotime($start));
$end   = date("g:i", strtotime($end));

echo $start;// Print $start Variable
echo $end; // Print $end Variable
Mujahid Bhoraniya
  • 1,518
  • 10
  • 22