Jump to content

Calculate Datetime difference


bjory

Recommended Posts

Hi,

I wannna calculate the difference in hours from 2 datetime strings e.g. [color=red]10/08/2006 11:00:00 [/color] and [color=red]10/02/2006 12:00:00[/color]. As these strings are varchars in the database, I hope someone can give me some clues how I can calculate the hours and min difference between these 2 strings.

Thanks!
Link to comment
Share on other sites

[code]$time1 = strtotime("10/08/2006 11:00:00");
$time2 = strtotime("10/02/2006 12:00:00");

echo round(($time1 - $time2) / 86400, 2) . " Days Between Dates";[/code]

Adjust the division (the 86400) for different time spans to get hours and so on.  You could also break it out to days, hours, minutes, seconds by dividing and taking the remainder if you wanted.
Link to comment
Share on other sites

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.