Jump to content

[SOLVED] finding difference in time


php_novice2007

Recommended Posts

Hi,

 

I've got two timestamp strings, str1 and str2, in the format "yyyy-mm-dd hh:mm:ss". I want to do str1 - str2 and have the answer as in integer in seconds.

 

Is there a function out there that I can use or do I have to manually tokenise both strings and then do subtractions... cos I'm thinking its gonna get confusing if the day is different..

 

Thanks!

Link to comment
Share on other sites

Hi,

 

Now I want to find the midpoint in time between the two times.

 

I've tried doing:

 

$date_diff = date(strtotime($currentTime)) - date(strtotime($lastTime));

$midTime = date(strtotime($t_last)) + date(strtotime($date_diff / 2));

 

($currentTime and $lastTime are two strings in the format "yyyy-mm-dd hh:mm:ss", $date_diff is the time difference in seconds)

 

E.g. $lastTime="2007-05-18 07:43:22" $currentTime="2007-05-18 08:43:22"

the code gives $midTime="2365047802"

 

So I want $midTime = "2007-05-18 08:13:22"..

 

How do I do it..? :(

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.