npsari Posted March 6, 2009 Share Posted March 6, 2009 Hello there, I echo from my database the two variables $time1 & $time2 Here is the format of the Time $time1 = 08:24:02 $time2 = 20:34:47 I want to create an IF funtiocn which will echo the following... If the time difference is more than 15 minutes: Sorry, the time difference is more than 15 minutes If the time difference is less than 15 minutes: Your session is still active But i dont know how to subtract Time $result = $time2 - $time1 ; If($result > '15') { Echo "Sorry, the time difference is more than 15 minutes"; }else{ Echo "Your session is still active"; } I think this is wrong... Please show me how... Link to comment https://forums.phpfreaks.com/topic/148177-how-to-subtract-time/ Share on other sites More sharing options...
corbin Posted March 6, 2009 Share Posted March 6, 2009 You will have to split the numbers and then figure it out. http://php.net/explode Link to comment https://forums.phpfreaks.com/topic/148177-how-to-subtract-time/#findComment-777827 Share on other sites More sharing options...
shadiadiph Posted March 6, 2009 Share Posted March 6, 2009 i would say use $time1 = "08:24:02"; $time2 = "20:34:47"; $t1 = strtotime($time1); $t2 = strtotime($time2); the make the sum the value returned is in seconds so 15 minutes would be 900 Link to comment https://forums.phpfreaks.com/topic/148177-how-to-subtract-time/#findComment-777832 Share on other sites More sharing options...
corbin Posted March 6, 2009 Share Posted March 6, 2009 strtotime converts to a unix timestamp with out enough information to do so? I guess it just assumes the current day. Link to comment https://forums.phpfreaks.com/topic/148177-how-to-subtract-time/#findComment-777835 Share on other sites More sharing options...
shadiadiph Posted March 6, 2009 Share Posted March 6, 2009 I think you are right it assumes the current day I am using the same on my login security it works for that ok. Link to comment https://forums.phpfreaks.com/topic/148177-how-to-subtract-time/#findComment-777842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.