Calculating difference between two dates in MySQL
is really easy.Here’s how we can do it.
Let’s say dt1 and dt2 are the 2 columns in table table_name.Just replace dt1,dt2 and table_name in the queries below with our values.Difference between two dates stored as variables
SELECT UNIX_TIMESTAMP(dt2) - UNIX_TIMESTAMP(dt1) from table_name; Difference between two dates stored as variables
SET @dt1='2013-11-09 00:00:00';
SET @dt2='2012-10-07 00:00:00';
SELECT UNIX_TIMESTAMP(@dt2) - UNIX_TIMESTAMP(@dt1);