crashmaster Posted December 19, 2007 Share Posted December 19, 2007 Hi, I need help in "time" question. I have a file, which contains this 2007-12-19||14:55:05 What I want to do is to get difference between date and time now, and date and time stored in the files... Difference should be in minutes... for ex: file.txt => 2007-12-19||14:55:05 now: 2007-12-19||22:00:05 Difference = (file.txt - now) = 7h 5min = 425min Can somebody help me? thanks Quote Link to comment Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 $file = file('input.txt'); $now = time(); foreach($file as $line) { $line = str_replace('||', ' ', $line); $then = strtotime($line); echo "Difference: " . ($now - $then) . "<br />\r\n"; } That would be in seconds though... Quote Link to comment Share on other sites More sharing options...
chigley Posted December 19, 2007 Share Posted December 19, 2007 Perhaps use strtotime() to get the timestamps. Then take the smaller from the larger, and you have the difference in seconds. Then divide by 60 to get it in minutes 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.