Hi Mike,
One method that might work, without having to modify the existing Diff2Dates
function that is posted on Doug's site, is to do the following sequence:
1.) Calculate the average tenure length in days. You can use the built-in
DateDiff function, as long as you don't care if the result is an integer:
qryAvgTenure
SELECT Avg(DateDiff("d",[DateSignedUp],Date())) AS AvgTenure
FROM tblCustomers;
---> Returns 1565 (as of today, April 15, 2007)
2.) Using the above result, calculate a new (average) DateSignedUp value.
You can use the built-in DateAdd function.
AvgDateSignedUp
SELECT DateAdd("d",(-1)*[AvgTenure],Date()) AS AvgDateSignedUp
FROM qryAvgTenure;
---> Returns 1/1/2003 (as of today, April 15, 2007)
3.) Feed the result of #2, above, into the Diff2Dates function.
qryAvgTenureInWords
SELECT Diff2Dates("ym",[AvgDateSignedUp],Date(),True) AS AvgTenure
FROM qryAvgDateSignedUp;
---> Returns: 4 years 3 months (as of today, April 15, 2007)
Or, using "ymd" instead of "ym" as the first parameter:
SELECT Diff2Dates("ymd",[AvgDateSignedUp],Date(),True) AS AvgTenure
FROM qryAvgDateSignedUp;
---> Returns: 4 years 3 months 14 days (as of today, April 15, 2007)
That took three queries to get the result, without having to modify the
Diff2Dates function. However, it should be relatively easy to create a new
function that performs the first two calculations and then calls the
Diff2Dates function.
Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________