Jump to content

Calculate time difference


rashmi_k28

Recommended Posts

Hi,

 

Help me in calculating time differnence

 

select status,timestamp from `tablename` where date(timestamp)=date(2008-04-04);

 

The result what I get is

    1 | 2008-04-04 17:30:01 |

|      1 | 2008-04-04 17:40:01 |

|      1 | 2008-04-04 17:50:01 |

|      1 | 2008-04-04 18:00:01 |

|      1 | 2008-04-04 18:10:01 |

|      1 | 2008-04-04 18:20:02 |

|      1 | 2008-04-04 18:30:02 |

|      1 | 2008-04-04 18:40:01 |

|      1 | 2008-04-04 18:50:01 |

|      1 | 2008-04-04 19:00:02 |

|      1 | 2008-04-04 19:10:01 |

|      1 | 2008-04-04 19:20:02 |

|      1 | 2008-04-04 19:30:01 |

|      1 | 2008-04-04 19:40:01 |

|      1 | 2008-04-04 19:50:01 |

|      1 | 2008-04-04 20:00:01 |

|      1 | 2008-04-04 20:10:01 |

|      0 | 2008-04-04 20:20:01 |

|    0| 2008-04-04 20:30:01 |

|      1 | 2008-04-04 20:40:02 |

|      1 | 2008-04-04 20:50:01 |

|      1 | 2008-04-04 21:00:01 |

|      1 | 2008-04-04 21:10:01 |

|      1 | 2008-04-04 21:20:01 |

|      1 | 2008-04-04 21:30:01 |

|      0 | 2008-04-04 21:40:01 |

|      1 | 2008-04-04 21:50:01 |

|      1 | 2008-04-04 22:00:02 |

|      1 | 2008-04-04 22:10:02 |

 

Now how to calculate the time difference between the two fields when status is 0.

For example When status becomes 1 at 2008-04-04 20:40:02 so how can i calculate the difference as 20 minutes the status was down and when status is 0 at 2008-04-04 21:40:01 in the another row I should calculate the timediffernce as 10 min.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/105234-calculate-time-difference/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.