This topic is locked
[SOLVED]

 Time difference PHP

11/10/2014 9:42:36 AM
PHPRunner General questions
S
sickacid author

Hi, in import page, before record added i want to calcolate time difference between two Times, i've done this code:
$time1=strtotime($values['MattinoInizio']);

$time2=strtotime($values['MattinoFine']);

$differenza = $time2 - $time1;

$values['OreLavorate']=date('H:i:s', $differenza);
But the result is always wrong, for time1 = 8:00 time2 = 13:00 i get 6 hour of difference <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=22749&image=1&table=forumtopics' class='bbc_emoticon' alt=':unsure:' /> There is always 1 hour of difference.. why? Is correct put -3600 in $differenza ?

Admin 11/10/2014

According to PHP documentation at http://php.net/manual/en/function.date.php date() function returns time of the day as opposed to time difference. 'H' parameter returns hour value in the range of 0-23. You do need to subtract 3600 if you want to get the time difference.

$time1=strtotime($values['MattinoInizio']);

$time2=strtotime($values['MattinoFine']);

$differenza = $time2 - $time1;

$values['OreLavorate']=date('H:i:s', $differenza-3600);