...

View Full Version : comparing dates



puja
05-05-2006, 10:43 AM
hi

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

thanks

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

(enddate-startdate)/secondsinaday

www.php.net/date
www.php.net/time


it depends what format they are in your database as though

guelphdad
05-06-2006, 02: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, 07:51 AM
try with this function
//you have to input $dt_start, $dt_end dates as this format
//yyyy-mm-dd
/*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.*/
enjoy...
function is_date_greater($dt_start, $dt_end)
{
if(strtotime($dt_end) > strtotime($dt_start) )
{
return true;
}
return false;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum