Hi Rick, thank you for this UDF - it is very useful. Unfortunately I am having some challenges using it to generate 'x years y months z days'-type output in Word. Because of the way the DateDiff() function in VBA works, I find that I have to do a manual work-around to count the right number of years/months/etc if the day of the month or month of the year in the second date is before the day/month in the first date. For example, DateDiff(FirstDate, SecondDate, "m"), where FirstDate = 20/02/2002 and SecondDate = 15/08/2002 returns 6, when it should only be 5.
I've addressed this problem so that it seems to work in 99% of scenarios, but I'm still having the occasional problem where the number of years is miscounted, or where a day is dropped for some reason. The code I am using is below, and these are the results that it generates. I know this is a bit of a big one, but any assistance would be appreciated:
FirstDate SecondDate Result Comments 01/07/00 30/06/04 4 yrs 0 mths 0 days correct 30/07/11 30/06/13 2 yrs 11 mths 1 days should be 1 yrs 11 mths 1 days 15/02/02 20/08/02 0 yrs 6 mths 6 days correct 15/02/02 20/08/03 1 yrs 6 mths 6 days correct 20/02/02 15/08/02 0 yrs 5 mths 27 days correct 20/02/02 15/08/03 1 yrs 5 mths 27 days correct 20/08/01 15/02/02 0 yrs 5 mths 27 days correct 20/08/01 15/02/04 2 yrs 5 mths 27 days correct 01/07/00 30/06/01 1 yrs 0 mths 0 days correct 08/07/11 08/06/13 1 yrs 11 mths 1 days correct 30/10/96 30/08/05 8 yrs 10 mths 1 days
[td]correct12/06/85 12/06/86 1 yrs 0 mths 1 days correct 31/01/08 31/08/10 2 yrs 7 mths 0 days should be 2 yrs 7 mths 1 days 31/01/08 31/08/09 1 yrs 7 mths 0 days should be 1 yrs 7 mths 1 days 31/03/07 01/08/08 1 yrs 4 mths 2 days correct 31/03/07 01/08/12 5 yrs 4 mths 2 days correct 31/08/07 01/03/08 0 yrs 6 mths 2 days correct 31/08/07 01/03/12 4 yrs 6 mths 2 days correct
Bookmarks