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
https://forums.phpfreaks.com/topic/61473-solved-finding-difference-in-time/
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..? :(

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.