Subject: RE: Convert no. of days into year and month
Carl’s answer will give you an end date if you have the start date and number of days, or the start date if you have an end date and number of days. I have the feeling, though, that you have both a start and end date and want to get the number of years and months between them – and getting the number of days is a simple matter of subtracting then dividing by the number of seconds in a day.
There’s a bit more to getting the number of months, years and days between dates than subtracting and dividing. Here’s a formula I posted in the R4 & R5 forum in 2003:
startDate := Time1;
endDate := Time2;
startDay := @Day(startDate);
endDay := @Day(endDate);
startMonth := @Month(StartDate);
endMonth := @Month(endDate);
startYear := @Year(startDate);
endYear := @Year(endDate);
lessAYear := @If(endMonth > startMonth;@False; (endMonth = startMonth) & (endDay >= startDay); @False; @True);
yearsDiff := @If(lessAYear; endYear - startYear - 1; endYear - startYear);
@Set(“endDate”; @Adjust(endDate;-yearsDiff;0;0;0;0;0));
monthAdj := @If(startDay>endDay;-1;0);
monthsDiff := @If(lessAYear; (endMonth + 12) - startMonth + monthAdj; endMonth - startMonth + monthAdj);
@Set(“endDate”;@Adjust(endDate;0;-monthsDiff;0;0;0;0));
daysDiff := @Integer((endDate - startDate)/86400);
@Prompt([Ok];“”;@Text(yearsDiff) + “years, " + @Text(monthsDiff) + " months, and " + @Text(daysDiff) + " days.”)