Note that there are some explanatory texts on larger screens.

plurals
  1. POdate format in PHP date function
    text
    copied!<p>Hi I have values stored in MSSQL database as time(7)</p> <p>job_start job_end</p> <p>I am trying to work out the difference between these two times using php, i have the folowing code</p> <pre><code>$start = $model-&gt;job_start; $end = $model-&gt;job_end; $diff = date( "h:i:s", strtotime($end) - strtotime($start) ) ; echo $diff ; </code></pre> <p>However the output is</p> <pre><code>03:06:00 </code></pre> <p>Rather than</p> <pre><code>00:06:00 </code></pre> <p>By the way the difference is 6 minutes (360 seconds), can anyone help get this in the right format so i can save it ? </p> <p>This question has been marked as a duplicate, however it is a different question as this addresses a specific timezone question when using the date function. And has been answered as such. </p> <p><strong>EDIT</strong></p> <p>The code i have marked answered the question i asked however I am trying to add an extra calculation as follows</p> <pre><code>$start = $model-&gt;job_start; $end = $model-&gt;job_end; $total = $model-&gt;customer-&gt;total_time; //adding time difference to total time used for that customer $dt = strtotime($total) + strtotime($end) - strtotime($start); $hours = floor($dt / 3600); $minutes = floor($dt / 60) - $hours * 60; $seconds = $dt - $hours * 3600 - $minutes * 60; // Padded values $hours = str_pad($hours, 2, STR_PAD_LEFT, '0'); $minutes = str_pad($minutes, 2, STR_PAD_LEFT, '0'); $seconds = str_pad($seconds, 2, STR_PAD_LEFT, '0'); $output = "{$hours}:{$minutes}:{$seconds}" ; //display echo '&lt;br&gt; Start time : '. $start; echo '&lt;br&gt; End time : '. $end; echo '&lt;br&gt; total time + time difference : '. $output; echo '&lt;br&gt; Total time for Customer : '. CHtml::encode($model-&gt;customer-&gt;total_time); </code></pre> <p>I am trying to add the difference between the total times to a total time variable However when output is echoed i get this display</p> <pre><code>Start time : 11:45:00.0000000 End time : 12:45:00.0000000 total time + time difference : 382015:00:00 Total time for Customer : 09:00:00.0000000 </code></pre> <p>Note that the total time + time difference has extra digits before it , its probably a simple mistake on my part but I can't see it , any help would be appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload