Using two date-and-time values that lie a week apart
mysql>
mysql> SET @dt1 = '1800-02-14 07:30:00';
Query OK, 0 rows affected (0.00 sec)
mysql> SET @dt2 = '1800-02-21 07:30:00';
Query OK, 0 rows affected (0.00 sec)
mysql> SET @interval = ((TO_DAYS(@dt2) - TO_DAYS(@dt1)) * 24*60*60) + TIME_TO_SEC(@dt2) - TIME_TO_SEC(@dt1);
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @interval AS seconds;
+---------+
| seconds |
+---------+
| 604800 |
+---------+
1 row in set (0.00 sec)
mysql>
Related examples in the same category