temujinleal Posted January 5, 2008 Share Posted January 5, 2008 Good day!! i would like to ask, how can i make an SQL statement if i'm going to find out the range of dates.. Because i'm making my simple project for school and it is related to reservation.. if i have check in date time of 2007-01-05 13:00:00 and check out date time of 2007-01-15 12:00:59, how can i make an SQL statement for that range of time? i will use that dates so that i cannot select the rooms that are already been used and reserved for that particular date time... thanks!! cheers!! Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/ Share on other sites More sharing options...
jvrothjr Posted January 5, 2008 Share Posted January 5, 2008 look into the betwen clause of the where statment Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-431152 Share on other sites More sharing options...
temujinleal Posted January 5, 2008 Author Share Posted January 5, 2008 sir is there any alternative aside from using the BETWEEN clause so that i can also try the others for accuracy.. thanks!! cheers!! Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-431181 Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 $startdate = mktime (0,0,0, $month, 1, $year); $enddate = mktime (23,59,59,$month, $days_in_month, $year); $query = "SELECT rid, rdate, rdesc FROM reservations WHERE rdate >= '$startdate' and rdate <= '$enddate' ORDER BY rdate ASC"; This is what I use for my reservation listings, it will query only 1 month of data Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-431241 Share on other sites More sharing options...
fenway Posted January 5, 2008 Share Posted January 5, 2008 sir is there any alternative aside from using the BETWEEN clause so that i can also try the others for accuracy.. thanks!! cheers!! Accuracy? What are you talking about? The php equivalent is slower and worse... definitely not more accurate. Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-431486 Share on other sites More sharing options...
temujinleal Posted January 6, 2008 Author Share Posted January 6, 2008 Accuracy? What are you talking about? The php equivalent is slower and worse... definitely not more accurate. sir what i mean is the result of the query... $startdate = mktime (0,0,0, $month, 1, $year); $enddate = mktime (23,59,59,$month, $days_in_month, $year); $query = "SELECT rid, rdate, rdesc FROM reservations WHERE rdate >= '$startdate' and rdate <= '$enddate' ORDER BY rdate ASC"; sir how about if i have field for check in date and another field for check out date? thanks!! Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-431523 Share on other sites More sharing options...
revraz Posted January 6, 2008 Share Posted January 6, 2008 Then use those dates instead. The important thing to notice is how I did my WHERE clause Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-431524 Share on other sites More sharing options...
temujinleal Posted January 6, 2008 Author Share Posted January 6, 2008 sir if i will have this example sql: SELECT tbl_booking.FK_rooms FROM tbl_booking WHERE tbl_booking.check_in_date BETWEEN '2008-01-07 08:00:00' AND '2008-01-08 07:50:00' OR tbl_booking.check_out_date BETWEEN '2008-01-07 08:00:00' AND '2008-01-08 07:50:00' then i have this data: tbl_booking ------------------------------------------------- check_in_date | check_in_time 2008-01-06 08:00:00 | 2008-01-09 12:50:00 ------------------------------------------------ their datatypes are DATETIME i can't select it.. :'( i used to try the DATE datatype and the values were just the date, the sql statement works.. but i must consider the time so i changed it to DATETIME but it fails to select... how can i make this sql statement possible to return accurate results with my sample data? thanks!! Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-431875 Share on other sites More sharing options...
temujinleal Posted January 7, 2008 Author Share Posted January 7, 2008 up!! Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-432498 Share on other sites More sharing options...
temujinleal Posted January 7, 2008 Author Share Posted January 7, 2008 up! Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-432693 Share on other sites More sharing options...
fenway Posted January 7, 2008 Share Posted January 7, 2008 up!! You expected a reply at 2AM? Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-432714 Share on other sites More sharing options...
temujinleal Posted January 8, 2008 Author Share Posted January 8, 2008 You expected a reply at 2AM? sir i'm just making this post updated.. Link to comment https://forums.phpfreaks.com/topic/84613-sql-statement-help/#findComment-433350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.