8 Replies Latest reply on Jul 21, 2010 3:57 PM by ChrisElliot

# calculating the number of days within a period of time.

### Title

calculating the number of days within a period of time.

### Post

Hi , I would be grateful for some help .

I am trying to come up with a formula to work out how many days a contract has to run within a specific year. For example the contract starts on December 1, 2009 and ends on Dec 1st 2010.  I need to work out how many days of the contract are within the 2010 calendar year .

Any assistance with this is most appreciated.

• ###### 1. Re: calculating the number of days within a period of time.

If you are storing the contract start and end dates in separate date fields, a simple subtraction can compute the number of days.

ContractEndDateField - Date ( 1 ; 1 ; 2010 ) will work.

If you want this for number of days in the current year, use:

ContractEndDateField - Date ( 1 ; 1 ; Year ( Get ( CurrentDate ) )

This works because date fields are really just specially formatted number fields that record the dates as the number of days since December 31, 0000

• ###### 2. Re: calculating the number of days within a period of time.

I do have start and end dates in separate fields . I think I am  beingpretty dense as I am having a hard time getting this to work .

When I try the second formula as follows

ExpirationdateforIHS-Date ( 1 ; 1 ; 2010(Get(CurrentDate))

It tells me an operator is expected here (Get

• ###### 3. Re: calculating the number of days within a period of time.

You should be using either:

ContractEndDateField - Date ( 1 ; 1 ; 2010 ) if you always want the days from January first of 2010

or you should use:

ContractEndDateField - Date ( 1 ; 1 ; Year ( Get ( CurrentDate ) ) if you want the days from January first of this year.

You appear to have combined the two examples that's resulting in incorrect syntax and an error message.

• ###### 4. Re: calculating the number of days within a period of time.

> how many days a contract has to run within a specific year.

How do you select the "specific year"? Is it always the current year?

Note that a contract can be entirely within the specified year, partially overlapping the year (front or back) or not at all - IOW you need to base your calculation on four dates.

• ###### 5. Re: calculating the number of days within a period of time.

I don't think I am explaining this very well so my apologies.

It would always be with the current year but at different times of the year. for example as of 7/21/2010 how may days remain on the contract that was effective 12/1/2009. The contracts are always 12 months long.

• ###### 6. Re: calculating the number of days within a period of time.

Thanks for pointing that out.

Perhaps this will serve:

Let ( [ d1 = Max ( ContractStartDate ; Date ( 1 ; 1 ; Year ( get ( CurrentYear ) ) ) ;
d2 = Min ( ContractEndDate ; Date ( 12 ; 31 ; Year ( get ( CurrentYear ) )) ] ;
d2 - d1
)

• ###### 7. Re: calculating the number of days within a period of time.

So its really three dates I guess.

A:Start of the year

B:days remaining as specified date

C:contract expiration date (which could be before or after B)

• ###### 8. Re: calculating the number of days within a period of time.

Thanks PhilModjunk I wil give that a try