Return to Snippet

Revision: 24047
at February 19, 2010 12:06 by bradless


Initial Code
SELECT DATEDIFF(
 (SELECT DATE(date_field) FROM table WHERE id = '1' AND status_id = '2' ORDER BY date_field DESC LIMIT 1),
 (SELECT DATE(date_field) FROM table WHERE id = '1' AND status_id = '1' ORDER BY date_field DESC LIMIT 1)
	) AS difference

Initial URL

                                

Initial Description
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.

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

Initial Tags
mysql, date

Initial Language
MySQL