MySQL time filtering tricks

I needed to filter rows using timestamp columns but with extra in-deep conditions such as:

- Looking up rows with the "lastRestart" column 2 minutes (or more) before now.
`lastRestart` < (NOW() - INTERVAL 2 MINUTE)

- Or instead of the literal value '2', you can reference a coloumn by it's name:
`lastRestart` < (NOW() - INTERVAL `Frequency` MINUTE)

- Comparing time fields with timestamps. Which means that you need to compare only hours, minutes and seconds with timestamp values\coloumns.
start_timeofday <= CAST(NOW() AS TIME)-- start_timeofday is a time coloumn.


Popular posts from this blog

Testing SOAP services using pingdom