MySQL Time Comparison

1

I have a schedule where I register an appointment, this appointment has Hora Inicial and Hora Final . But now when I register a new appointment I have to do a check to see if the hours are not between the hours already registered. Example:

I have an appointment with Start Time 13:00 and End Time: 14:00 As of today. How do I check this period of time to not allow anything to be recorded in this range of 13:00 as 14:00 ?

    
asked by anonymous 10.07.2015 / 20:18

1 answer

3

To find records between two dates in MySQL, you can use the BETWEEN .

If it is a column of type datetime :

SELECT *
FROM 'minhaTabela'
WHERE 'campoDatetime' BETWEEN '2015-07-10 13:00:00' AND '2015-07-10 14:00:00';

If it is a column of type time :

SELECT *
FROM 'minhaTabela'
WHERE 'campoTime' BETWEEN '13:00:00' AND '14:00:00';

If the query returns 1 or more results, then you know there are already appointments.

    
10.07.2015 / 21:07