Jump to content

Date Time Difference Issue


honkmaster

Recommended Posts

Hi, I have two date and time stamps stored in my database, I'm using the below script to calculate the difference but whenever I'm getting an extra 1 hour added ?? Any ideas, Cheers Chris

<?php
$start = $row_rsComplete['quote_added'];
$finish = $row_rsComplete['quote_complete'];
$difference = ($finish - $start);
$day = round(($difference % 604800) / 86400); 
$hours = round((($difference % 604800) % 86400) / 3600); 
$minutes = round(((($difference % 604800) % 86400) % 3600) / 60); 
echo $day." days"."<br/>";
echo $hours." hours"."<br/>";
echo $minutes." minutes"."<br/>";
?>
Link to comment
Share on other sites

a) it would have been nice if you posted what the input data values were that produce the incorrect result.

 

b) there aren't the same number of hours in each day, especially if you observe Daylight Savings Time in your time zone.

 

c) if you use your database's or php's date/time functions to perform the calculation, it will probably take into account any DST change.

Link to comment
Share on other sites

Below is code with posted data, result is 1 hr 43 mins which is incorrect, start time is 13:12 and finish is 13:55 which is 43 mins

<?php
$start = '1491480732';
$finish = '1491483308';
$difference = ($finish - $start);
$day = round(($difference % 604800) / 86400); 
$hours = round((($difference % 604800) % 86400) / 3600); 
$minutes = round(((($difference % 604800) % 86400) % 3600) / 60); 
echo $day." days"."<br/>";
echo $hours." hours"."<br/>";
echo $minutes." minutes"."<br/>";
?>
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.