Calculating number of days between two dates

Calculating number of days between two dates

Can this be done, perhaps as a custom function?  
If I subtract date2 from date1 I get a (large) integer, which suggests that dates are just integers under the hood.  So there would be a way to do element date match.  A good example might be to calculate accounts receivable aging...a fairly common sort of thing.  Before I try to hack my way through this, is there a straightforward method or has someone written code they would be willing to share?

Thanks!