rashmi_k28 Posted May 29, 2008 Share Posted May 29, 2008 Hi, The fields of a table are status,timestamp,name. Status is 0 or 1 Timestamp is increment of 10 minutes. I have to calculate the timestamp from when status is from 0 to 1. | 0 | 2008-05-29 14:10:02 |A | 0 | 2008-05-29 14:20:02 |A | 1 | 2008-05-29 14:30:02 |A | 0 | 2008-05-29 14:40:02 |A | 1 | 2008-05-29 14:50:02 |A Here at 2008-05-29 14:10:02 status was 0 and at 2008-05-29 14:30:02 status was 1. So I have to calculate the difference between two. And again from 2008-05-29 14:40:02 to 2008-05-29 14:50:02 When I use the below code I get time difference as 20 min and 20 min. I have used the code as $currentStatus = $result['status']; $currentTime = $result['timestamp']; $previousStatus = $previousStatus == '' ? $currentStatus : $previousStatus; $previoustime = $previoustime == '' ? $currentTime : $previoustime; if($previousStatus == $currentStatus) { $previousStatus=$currentStatus; // $previoustime=$currentTime; continue; } $d = strtotime($currentTime) - strtotime($previoustime); //array_push($records,"$result[2]#$ip[0]#$result[2]#$result[1]#$previoustime#$d"); array_push($records,"$result[2]#$ip[0]#$result[2]#$previoustime#$result[1]#$d"); $previousStatus = $currentStatus; $previoustime=$currentTime; But the calculation is not proper. The previoustime is creating problem. It is taking the currenttime of previous row as the next previoustime. And if status is 0 through out the day then how to add the condition and calculate time differnce from first row and last row. Please help me how to solve this problem 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.