Hello,

I have 2 dates i.e: Arrival Date and Departure date from user.

Now i have dates in database like same as above. I want to make sure that there's no clash between the dates entered by customer with the dates in database.

For example: If my arrival date is: 10-1-2005 and departure date is: 17-1-2005 and date in db's are:

  1. 3-1-2005 to 10-1-2005
  2. 11-1-2005 to 18-1-2005
  3. 9-1-2005 to 15-1-2005
  4. 10-1-2005 to 17-1-2005

So if it compares with date 1 then it should say available but it should say not available when compared with date 2 and 3 and 4.

So there should be no clash of dates at all with the range..provided by user with the dates in db. If there is a clash then say "not available" and if there is no clash then say: "available".

Can someone help me with this ? As i am trying to figure it out for days now and i have reached no where.

Or maybe just tell me the logic on how to check or compare dates for clashes then i will do it.

Any help will be highly appericiated.

Thanks.

    Hi,

    For exmaple if arrical date is: 10-1-2005 then in db if there are 1000 different ranges are available then it should check with all 1000 ranges that 10-1 des not falls in the range or is not equal to any arrival or departure date in the db.

    So means lets say if we have a date in db which says : 7-1-2005 to 17-1-2005 then its a clash with 10-1-2005 and should say: not available. And also if we have a date range in db like: 12-1-2005 to 22-1-2005 then it should also say not available becuase its still clashing with the date provided with user becuase his date is from 10 to 17 and 12,13,14,15,16 are between 12 to 22 so its a clash.

    Only dates whcih do not clash at all or come in between each other are acceptable.

    Do you get my point ?

    Thanks.

      You could take a look at the http://www.php.net/manual/en/function.strtotime.php function in the manual. This will allow you to convert a date to an integer, which you can then use to validate dates against one another.

      I think this can be done directly as a query in the database, but I would do it in PHP itself.

      If you need more inspiration let us know.

        The dates should be YYYY-MM-DD in the database, that way you can use standard operators to compare them.

          Hi,

          I was already doing comparison by converting the dates to unix timestamp but if you read my 2nd post then you see i am getting that problem.

          And mmonaco i have dates in that format in database. So can you guy help me geting the logic right ? This is basically a room reservation thing and i think now you got my point how it should be.

          I am just not able to get the right results when its coming to comparing dates. rest everything i have made.

          Thanks.

            Two date ranges won't clash if either ends before the other begins. In other words, if the ending date of one is less than the starting date of the other.

              Hi,

              Thanks i have solved my problem on my own.

              Thanks again.

                Write a Reply...