Subject: Computing for the No of Months and Days in Date Range
Assuming your month is a true calendar month, the following formula determines the number of months between two dates, assuming that each change of month means another month has passed. It computes number of months by subtracting the ending month number, from the beginning month number and then adds 12 months for each year that has passed.For example, from December 31, 1999 to January 1, 2000, the answer is one month by evaluating this as 1 - 12 + 12
If the two dates are in the same month and year, the returned result is a 0 (zero).
If the two dates are in the same month but the second date is the following year, the returned result is 12.
StartDate and EndDate are the input dates.
Note: You could save your field returning errors, if you add something like this…
@If( @IsAvailable( StartDate ) & @IsTime( StartDate ) &
@IsAvailable( EndDate ) & @IsTime( EndDate ); @Success; @Return( "" ) );
vSD := StartDate;
vED := EndDate;
@Month( vED ) + ( 12 * ( @Year( vED ) - @Year( vSD ) ) - @Month( vSD ) );
This is a variation of the previous formula. It assumes that a month has not passed, until you have passed the day of the month in which you began the starting date.
For example the difference between January 15 1999 and February 1, 1999 is 0 months because we have not yet reached February 15.
vSD := StartDate;
vED := EndDate;
( ( @Month( vED ) + ( 12 * ( @Year( vED ) - @Year( vSD ) ) ) - @Month( vSD ) ) - ( @If ( @Day( vED ) <= @Day( vSD ); 0; 1 ) ) );
Hope the above helps a bit.
Afraid I have to go throw a spanner at a server, so I’ll try to come back later with Days, if no one else does.