mySQL datetime comparing syntax error
I am making a booking system for my mother and I have some problems locking already booked times.
Here is the code:
SELECT event_start
FROM annagretasjobe开发者_如何学JAVArg
WHEREevent_start BETWEEN 2011-8-1 1:30:00 AND 2011-8-1 2:0:00
Here is the reply from the mySQL server:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1:30:00 and 2011-8-1 2:0:00' at line 1
Date datatype must be enclosed in quotes:
select event_start from annagretasjoberg where event_start
between '2011-8-1 1:30:00' and '2011-8-1 2:0:00'
You need to put your example dates in single quotes in order for SQL to parse it correctly:
SELECT event_start
FROM annagretasjoberg
WHERE event_start BETWEEN event_start between '2011-8-1 1:30:00' and '2011-8-1 2:0:00'
Put quotes around your dates:
SELECT event_start
FROM annagretasjoberg
WHEREevent_start BETWEEN '2011-8-1 1:30:00' AND '2011-8-1 2:0:00'
You have to put the date values between single quotes, e.g.
select event_start from annagretasjoberg where event_start between '2011-8-1 1:30:00' and '2011-8-1 2:0:00'
I also would encourage you to use parametrized queries.
精彩评论