QA.TechInterviews.com - your tech questions answered
How To Write Query To Count Number Of Night Between Arrival Date And Departure Date?
I am doing hotel reservation system. Can anybody help me in write query for count the number of night for guests stay?
Example arrival date is 28-09-2006 and departure date is 30-09-2006. That means this guest is staying for 2 nights. So is 28-09-2006 night and 29-09-2006 night. How i want to write the query for count between the arrival date and departure date? Anybody have any idea?
Pls help :) TQ.
in php language
yup is two night. 28-09-2006 till 30-09-006. That means that guest is staying 28-09-2006 abd 29-09-2006 nights. So is 2 nights. Hw to write query to count between that 2 days?
28-09-2006 that guest is staying and 29-09-2006 also the guest stay. 30-09-2006 guest is check out already. So it 2 nights. How to write query to count between arrival date(28-09-2006) and departure date(30-09-2006)
what language?

mktime() makes the date.. then subtract the 2 unix timestamps and then you can divide it out to get to the precision you want.

If you have another way of making the time stamp that would also work, but the mktime() will work if nothing else
You didn't say but if you are doing SQL queries you can write a query that will automatically calculate the number of days between two dates. In SQL help look under "date calculations"
I'm not sure I understand your question. Yes

9/28/06-9/30/06 Is a 2 night hotel stay.
9/28/06-9/29/06 Is One night

Write a query?
what language?

mktime() makes the date.. then subtract the 2 unix timestamps and then you can divide it out to get to the precision you want.

If you have another way of making the time stamp that would also work, but the mktime() will work if nothing else
The easiest way is to convert the date into number of days elapsed since January 1, 1904 and subtract he arrival date from the departure date. There are several standard algorithms to do this. That will give you the correct number of days.

Use your favourite search engine to find date calculation algorithms for the programming language you are using, and it should take you only a few minutes to put this together.

Here is a page that gives a simple algorithm and source code examples: http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html
In php language I can't tell you. In an MS Access Database, (similar to SQL language) in query design you create a field with the following control:
=[Departure Date field]-[Arrival Date field]
I'm pretty sure you can find that formula in Excel. Just write it in the help clip. If I have some time I will try to find it and put it in here.

Hope that helps.

Back to QA. TechInterviews.com. Powered by Yahoo! Answers and TechInterviews.com community.