sqlmysql

WHERE clause to filter times that are under an hour


SELECT 
    name,
    start_time,
    TIME(cancelled_date) AS cancelled_time,
    TIMEDIFF(start_time, TIME(cancelled_date)) AS difference
FROM
    bookings

I'm trying to get from the database a list of bookings which were cancelled with less than an hour's notice. The start time and the cancellation times are both in TIME format, I know a timestamp would have made this easier. So above I've calculated the time difference between the two values and now need to add a WHERE clause to restrict it to only those records that have a difference of under 1:00:00. Obviously this isn't a number, it's a time, so a simple bit of maths won't do it.


Solution

  • you can use having difference<time('1:00')