By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,643 Members | 1,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,643 IT Pros & Developers. It's quick & easy.

Comparing Dates

P: 9
I am using the PHP.MYSQL and Apache server application in developing my website. I have problem in comparing dates. Website has room reservation, the user will check first the room availability. The user will input dates using the combo box like cboyear,cboday and cbomonth. What SQL statement or quey should I write to compare it to the database. The database has already have value in dates. I want to compare the input date to the database.... What is the query of this..


Please somebody help me....
Jan 20 '07 #1
Share this Question
Share on Google+
4 Replies


P: 4
Here is one way, it requires that your dates are entered in by the unixtime function

[php]
$unixtime = strtotime('now');

mysql_select_db("yay") or die(mysql_error());
$query = "SELECT * FROM tablename WHERE this = '$that' AND expires_on >= '$unixtime'"; [/php]

expires_on is one of the column names so in yours it may be

[php]AND listed >= '$unixtime'"[/php]
Jan 20 '07 #2

P: 4
This wont let me edit since its past 5 min, so I will repost

Here is one way, it requires that your dates are entered in by the unixtime function, which they may already be, and they may be translated out of..

[php]
$nice_post = date('F d Y', $this);
//This will return the variable $this from unix time to a readable date

$unixtime = strtotime('now');
//makes current time into unix time string

//Can also be used like
$time = strtotime("10 September 2000")

mysql_select_db("yay") or die(mysql_error());
$query = "SELECT * FROM tablename WHERE this = '$that' AND time >= '$unixtime'";

//of course other variations would be = < or >[/php]

expires_on is one of the column names so in yours it may be
Jan 20 '07 #3

cassbiz
100+
P: 202
Hi Cheryl,

I am working on a very similar project. Ronverdonk posted this earlier and here is a great query to check for date availability.

[php]
<?
$query = "(SELECT * FROM table WHERE date BETWEEN '$var_from' AND '$var_to'
OR date1 BETWEEN '$var_from' and '$var_to';)";
?>
[/php]
Jan 20 '07 #4

cassbiz
100+
P: 202
There is one more note that I found is that the arrival date must be plus 1 day when comparing to a room becoming available. Otherwise the room will say occupied when it is really available.
Jan 20 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.