calculate the difference between dates in one columns within the same table


/ Published in: MySQL
Save to your folder(s)

I use something similar to the example to get the difference between statuses in a status log table that I have. It comes in handy when determining the number of days between status changes. This works in MySQL 5.0.


Copy this code and paste it in your HTML
  1. (SELECT DATE(date_field) FROM table WHERE id = '1' AND status_id = '2' ORDER BY date_field DESC LIMIT 1),
  2. (SELECT DATE(date_field) FROM table WHERE id = '1' AND status_id = '1' ORDER BY date_field DESC LIMIT 1)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.