klenwell information services : MysqlInterval

Mysql Interval

return to DevMysql

Examples

mysql> SELECT DATE(NOW()) - INTERVAL 1 DAY;
+------------------------------+
| DATE(NOW()) - INTERVAL 1 DAY |
+------------------------------+
| 2010-07-06                   |
+------------------------------+
1 row in set (0.00 sec)

mysql> SELECT NOW() - INTERVAL 1 DAY;
+------------------------+
| NOW() - INTERVAL 1 DAY |
+------------------------+
| 2010-07-06 09:02:41    |
+------------------------+
1 row in set (0.00 sec)

SET @d='2010-06-01'; 
SELECT COUNT(*) AS transaction_count FROM transactions WHERE lastupdate >= @d - INTERVAL 1 DAY and lastupdate < @d;


References

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add