newbiePHP Posted December 7, 2007 Share Posted December 7, 2007 Hey guys, I have read so much stuff on timestamps over the last few hours that i think my head has melted. I have a very simply problem. I have 2 timestamps and I need to find the time between them. I include a bit of the code I'm using. I know from echos that $Realtime[0]= 2007-08-28 15:24:44 and $Timestamp[1]= 2007-08-28 10:00:01 but when i echo out $Realtime[1] i just get 0. I'm going to be taking timestamps away from each other a lot so I'm going to write a function that takes in 2 timestamps and returns there difference in H:m:s Can someone help me with this please. $Realtime[1] = $Realtime[0] - $Timestamp[1]; Any help would be great!! Thanks Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 7, 2007 Share Posted December 7, 2007 strtotime might convert those to native Unix timestamps. You need to have it in Unix format to subtract... then you will need to convert it back into something meaningful to look at. PhREEEk Quote Link to comment Share on other sites More sharing options...
newbiePHP Posted December 7, 2007 Author Share Posted December 7, 2007 hey PHP_PhREEEk, strtotime didn't seem to work. What parameters do you need to pass? I just typed strtotime($Realtime[0]); but it gave an error Thanks for the reply Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 7, 2007 Share Posted December 7, 2007 <?php $data = '2007-08-28 15:24:44'; $data = strtotime("$data"); echo "We converted 2007-08-28 15:24:44 to a Unix Timestamp: $data<br><br>"; echo "When converted back with date(), we get: " . date('Y-m-d H:i:s', $data); PhREEEk Quote Link to comment Share on other sites More sharing options...
newbiePHP Posted December 7, 2007 Author Share Posted December 7, 2007 Thats great PhREEEk Thanks. Just one last thing. if I had $data = '2007-08-28 15:24:44'; How do I get $data=15:24:44; In other words how do i knock of the date and just be left with the time? Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 7, 2007 Share Posted December 7, 2007 <?php $data = '2007-08-28 15:24:44'; $data = strtotime("$data"); echo "We converted 2007-08-28 15:24:44 to a Unix Timestamp: $data<br><br>"; echo "When converted back with date(), we get: " . date('H:i:s', $data); lol... time and date stuff is really easy... PhREEEk Quote Link to comment Share on other sites More sharing options...
newbiePHP Posted December 7, 2007 Author Share Posted December 7, 2007 Thanks for your help Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 7, 2007 Share Posted December 7, 2007 Quite welcome! = ^) PhREEEk 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.