php_novice2007 Posted July 24, 2007 Share Posted July 24, 2007 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 More sharing options...
trq Posted July 24, 2007 Share Posted July 24, 2007 date(). Link to comment https://forums.phpfreaks.com/topic/61473-solved-finding-difference-in-time/#findComment-305965 Share on other sites More sharing options...
php_novice2007 Posted July 27, 2007 Author Share Posted July 27, 2007 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 https://forums.phpfreaks.com/topic/61473-solved-finding-difference-in-time/#findComment-308535 Share on other sites More sharing options...
hitman6003 Posted July 27, 2007 Share Posted July 27, 2007 <?php $lastTime = "2007-05-18 07:43:22"; $currentTime = "2007-05-18 08:43:22"; echo date("Y-m-d H:i:s", strtotime($lastTime) + (floor( (strtotime($currentTime) - strtotime($lastTime)) / 2) ) ); ?> Link to comment https://forums.phpfreaks.com/topic/61473-solved-finding-difference-in-time/#findComment-308547 Share on other sites More sharing options...
php_novice2007 Posted July 27, 2007 Author Share Posted July 27, 2007 Thanks~! Link to comment https://forums.phpfreaks.com/topic/61473-solved-finding-difference-in-time/#findComment-308635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.