Hello i have a SQL Table which look like this:
RESERVATIONROOM:
ID NAME FROMDATE TODATE
5 Room1 2012-11-29 11:46:00.000 2012-11-29 12:45:00.000
6 Room1 2012-11-29 12:55:00.000 2012-11-29 14:20:00.000
7 Room1 2012-11-29 15:00:00.000 2012-11-29 16:42:00.000
I have a from and a to date and i want to select all rooms which are between those two dates.
Example:
form date: 2012-11-29 11:50:00.000
to date: 2012-11-29 13:46:00.000
The output should be like this:
RESERVATIONROOM:
ID NAME FROMDATE TODATE 5 Room1 2012-11-29 11:46:00.000 2012-11-29 12:45:00.000 6 Room1 2012-11-29 12:55:00.000 2012-11-29 14:20:00.000
This is what i have so far:
SELECT*
FROM RESERVATIONROOM
WHERE FROMDATE BETWEEN CONVERT(DATETIME,'2012-11-29 11:50:00.000',101) AND CONVERT(DATETIME,'2012-11-29 13:46:00.000',101)
AND TODATE < CONVERT(DATETIME,'2012-11-29 13:46:00.000',101)
ORDER BY FROMDATE ASC
My Select Statement filters to much and i cant see all the dates which are between those two dates.
Am i missing something?
Thanks in advance for your help
Sorry for convert comment, i thought it was datetime to varchar convert.
But from your input date, you gave two date and table has two date for each room. It is actually confusing what are these from dates and to dates. From your example output, you should use
orbetween two filter. Look here.Good luck.