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! Quote Link to comment Share on other sites More sharing options...
trq Posted July 24, 2007 Share Posted July 24, 2007 date(). Quote Link to comment 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..? Quote Link to comment 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) ) ); ?> Quote Link to comment Share on other sites More sharing options...
php_novice2007 Posted July 27, 2007 Author Share Posted July 27, 2007 Thanks~! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.