Avg Days to Pay

Avg Days to Pay

Does anyone have the Average Days to Pay SQL calculation?   Trying to replicate this number for a report.  I can get close but not exact.

Currently using MIN(EffectiveDate) for invoicedate and MAX(EffectiveDate) for PaymentDate.