Need excel formula to calculate the number of days in a date range, if they end within that range
October 1, 2009 7:15 AM
Subscribe
I need a formula to help calculate the number of days as compared to a range.
Importing a CSV for a query to show bookings within the date range of 9/1 to 9/30. Some bookings are booked through the entire month and some are partial. I need to figure out the number of days or percentage for the bookings that don't run all the way through the query range.
Query Start Date: 09/01/09
Query End Date: 09/30/09
Booking1 | 02/14/09 (booking start) | 10/14/09 (booking end)
Booking2 | 03/01/09 (booking start) | 09/15/09 (booking end)
Booking3 | 06/11/09 (booking start) | 12/31/09 (booking end)
So I know that Booking 1 and 3 go through the entire month of the query range (30 days), but I need a formula to figure out how many days are in Booking 2. I know that you can apply formula to each row to subtract dates, but I have hundreds of rows. I was thinking it would read something like: "If end date is less than query end date, then subtract booking end date from query start date (and add 1)." Maybe to take it further, "else sum is 30 days"
Any help is appreciated.
posted by malcommc to work & money (9 comments total)
In Excel You can subtract 2 dates to get the number of days between them.
{A1} : = 9/30/09 ; {B1} := 9/1/09
{C1} := =A1-B1 results in 29 days
I'll state a bunch of if statements for the next part
1st Category:
IF my start booking is LESS than my first date, I need to know information about my end booking:
(IF my end booking is LESS than my first date, I am not relevant
IF my end booking is GREATER than my first date, but is LESS than my second date, I am a partial month
IF my end booking is GREATER than my first date, and GREATER than my second date, I am a total booking)
2nd Category:
IF my start booking is GREATER than my first date, I need to know information about my end booking:
(IF my start booking is LESS than my first date, either an error check, or my Start/End booking are reverssed and should be treated as such
IF my end booking is GREATER than my, but is LESS than my second date, I am a partial month
IF my end booking is Greater than my first date, and GREATER than my second date, I am also a partial month)
3rd Category:
IF my start booking is GREATER than my second date, I am not not relevant.
Now in each of those questions, there are two dates that I should be using to measure the overlapped portion, and those should be identifiable.
posted by Nanukthedog at 7:45 AM on October 1