Jump to content

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
https://forums.phpfreaks.com/topic/303658-date-time-difference-issue/
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.

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/>";
?>
Edited by honkmaster
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.