Reputation: 1
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 annagretasjoberg
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
Upvotes: 0
Views: 2563
Reputation: 18041
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'
Upvotes: 3
Reputation: 4172
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.
Upvotes: 0
Reputation: 79556
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'
Upvotes: 2
Reputation: 494
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'
Upvotes: 2