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 Link to comment https://forums.phpfreaks.com/topic/82396-time-differents/ 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... Link to comment https://forums.phpfreaks.com/topic/82396-time-differents/#findComment-418853 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 Link to comment https://forums.phpfreaks.com/topic/82396-time-differents/#findComment-418854 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.