Re: Exact Date difference in Years,months and Days to be shown in Form Field.
Thanks guys spent ages trying to sort this out.
Made some slight changes to suit my needs, no doubt it would be cleaner in VBA.
I'm using it for an employment record. The current employment will have a blank "DateTo" there is the option of setting default to Date() but I want it shown blank for employment still running so I've added this in to cover it:
iif(isnull([DateTo]),Date(),[DateTo])
Combined Below.
=Int(DateDiff("m",[DateFrom],iif(isnull([DateTo]),Date(),[DateTo]))/12) & " Y: " & IIf(DatePart("d",iif(isnull([DateTo]),Date(),[DateTo]))-DatePart("d",[DateFrom])>=0,DateDiff("m",[DateFrom],iif(isnull([DateTo]),Date(),[DateTo]))-(Int(DateDiff("m",[DateFrom],iif(isnull([DateTo]),Date(),[DateTo]))/12)*12),DateDiff("m",[DateFrom],iif(isnull([DateTo]),Date(),[DateTo]))-(Int(DateDiff("m",[DateFrom],iif(isnull([DateTo]),Date(),[DateTo]))/12)*12)) & " M " & IIf(DatePart("d",iif(isnull([DateTo]),Date(),[DateTo]))-DatePart("d",[DateFrom])>=0,DateDiff("d",DateAdd("m",DateDiff("m",[DateFrom],iif(isnull([DateTo]),Date(),[DateTo])),[DateFrom]),iif(isnull([DateTo]),Date(),[DateTo])),DateDiff("d",DateAdd("m",DateDiff("m",[DateFrom],iif(isnull([DateTo]),Date(),[DateTo]))-1,[DateFrom]),iif(isnull([DateTo]),Date(),[DateTo]))) & " Days"
I'm thinking also perhaps to calculate out the zero values and their suffix when years or months = 0 but that's more faffing for another time