Jump to content

Recommended Posts

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

$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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.