I have four fields, using those I display the elapsed time between them. This is my php code:
// Days elapsed from the moment of the creation to the date of the visit
$date1 = $ticket->date_at;
$date2 = $ticket->visit_date;
$diff = abs(strtotime($date2) - strtotime($date1));
// Specific time elapsed between the dates, (days, months and years)
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
// Hours elapsed
$horallamada = strtotime($ticket->time_at);
$horavis = strtotime($ticket->visit_hour_in);
$horasal = strtotime($ticket->visit_hour_out);
$hdiff = $horallamada - $horasal;
$hvisdiff = $horallamada - $horavis;
$hsolution = $horavis - $horasal;
// printing of the time elapsed to answer the ticket
printf("<p>This ticket was answered in ");
echo gmdate("H:i", abs($hvisdiff)); printf(" hours.</p>");
// printing of the time elapsed to solve the ticket
printf("<p>This ticket was solved in ");
echo gmdate("H:i", abs($hsolution)); printf(" hours.</p>");
// total time elapsed calculation
printf("This ticket was closed in %d years, %d months, %d days and \n", $years, $months, $days);
echo gmdate("H:i", abs($hdiff)); printf(" hours after the date of creation.");
$hvisdiff
, $hsolution
and $hdiff
will return the difference as "02:36", that would be, 02 hours and 36 minutes.
How can I make it show like this?
Like:
This ticket was answered in 02 hours and 36 minutes
This ticket was solved in 01 hours and 6 minutes
This ticket was closed x years, x months, x days and 03 hours and 46 minutes after the date of creation.
I tried the following this tutorial, however, it wouldn't work. How can I achieve this?