5 Replies Latest reply on Aug 1, 2013 2:41 AM by MichaelMüller

# Count days from a range of dates and assigning it to the relevant months

### Title

Count days from a range of dates and assigning it to the relevant months

### Post

Hello,

I have a room reservations that start in one month and ends at another month

StartDate  10.1.2013

EndDate   10.3.2013

I need to count the days in each one of the months and eventually summarize all days in each of the months in a found set.

Michael

• ###### 1. Re: Count days from a range of dates and assigning it to the relevant months

You can have a caluclation field that has the end date subtracted by the start date.

Then have a summary field on the calculation field you created.

If I am understanding correctly.

• ###### 2. Re: Count days from a range of dates and assigning it to the relevant months

Thank you for the prompt answer.

The case is however, different.

From the following field:

StartDate  10.1.2013

EndDate   10.3.2013

The result should look like that:

1/2013 : 21

2/2013 : 28

3/2013 : 10

• ###### 3. Re: Count days from a range of dates and assigning it to the relevant months

Ah, I see, Your date format is day, month, year.

Anyways,

In a script I can imagine how to do this with a loop.

So if you start with the current month and loop through each month till you get to that last month, you can do the date subtraction.

In the loop you will have to check if the month that needs calculating is part of the start, end, or inbetween months.

If it is the start month, do the subtraction from the start date to the last day of month.

If it is an inbetween month do the subtraction of the first day of the month to the last day.

If it is an end month do the subtraction between the first day of the month and the end date.

This will give you the last day of the month:

If I think of simpler way, I'll let you know.

• ###### 4. Re: Count days from a range of dates and assigning it to the relevant months

Many times, it simplifies matters to have a table with one record for each day of the reservataion. Then you can simply count all the records for a given month to get the days reserved. This can also be a very useful table for checking for room availability.

• ###### 5. Re: Count days from a range of dates and assigning it to the relevant months

Thank you, it works.