View Full Version : comparing dates

05-05-2006, 11:43 AM

i want to compare two dates called booking_start_date and booking_end_date to make sure that the booking start date comes before the booking end date.

at the moment both dates are just stored as dates in the mysql database.

anybody know how i could do this?

and also does anybody know how i can find the number of days that the booking is for based on the dates that the user has entered as it will be needed for me to calculate the price of their overall booking


05-06-2006, 08:34 AM
with PHP timestamps its easy to find how many days between 2 dates.



it depends what format they are in your database as though

05-06-2006, 03:31 PM
Since you are working with data in a database, let the database do the calculations for you. You can use datediff to find the difference between the dates.

you can also take a look at the article in my signature on room reservations which will show you how to check for vacant rooms when you want to do a booking.

Aruna Attanayak
05-09-2006, 08:51 AM
try with this function
//you have to input $dt_start, $dt_end dates as this format
/*if your date is not in above format use php preg_split function to split your date by perticular characters then re organize them acording to above mentioned format.*/
function is_date_greater($dt_start, $dt_end)
if(strtotime($dt_end) > strtotime($dt_start) )
return true;
return false;