Reputation: 1016
I am currently trying to get all the appointments for a user out of the database based on the date they clicked on a calendar.
When clicked on the calendar a variable will get the value of eg. 20-06-2016 00:00:00
Now I want to return every appointment location of today using this date.
I use this query:
SELECT appo_location WHERE id = 'variable_id' AND date ='variable_date';
This is not really working. When i execute it says I have an error in my SQL statement. Also will my code get every appointment that is today when i use this: 20-06-2016 00:00:00 ? because it's only the start of the day.
This is my actual query:
query = "SELECT afspraak_locatie WHERE id = '" + item + "' AND datum = '" + datum +"'";
Upvotes: 1
Views: 926
Reputation: 6178
try this.
Create Table
CREATE TABLE A
(`id` int, `afspraak_locatie` varchar(1), `date` DATETIME)
;
INSERT INTO A
(`id`,`afspraak_locatie`, `date`)
VALUES
(1, 'A', '2016-06-20 14:30:00'),
(1, 'B', '2016-06-20 15:30:00'),
(1, 'C', '2016-06-20 16:30:00'),
(1, 'D', '2016-06-20 17:30:00'),
(2, 'E', '2016-06-20 15:30:00'),
(2, 'F', '2016-06-20 14:30:00'),
(2, 'G', '2016-06-20 13:30:00')
;
Query
SELECT afspraak_locatie
FROM A
WHERE id='1' AND DATE(date) = Date('2016-06-20 00:00:00')
Upvotes: 0
Reputation: 1320
If you want to get all data within the date, then you should compare only the date (excluding the time). You can use the DATE
function.
"SELECT afspraak_locatie FROM your_table_name
WHERE id = '" + item + "' AND DATE(datum) = DATE('" + your_date_variable + "')"
Upvotes: 2
Reputation: 399
date
should be [date]
. date
is keyword so you should use [date]
for your column name
in query. Hope it works!
EDIT
Your query is wrong. SELECT
(columns) FROM
(table). Where is FROM
keyword?
Upvotes: 2