| Column | C | D | E | F | G | H | I | J | |
| Row | I have two dates in excel I want to display the difference in months or days or years | ||||||||
| 1 | Date 1 | Date 2 | |||||||
| 2 | MM/dd/yyyy | Month Diff (result wanted) | |||||||
| 3 | 7/15/1999 | 9/30/2003 | 50 | ||||||
| 4 | 10/1/2003 | 3/31/2004 | 5 | ||||||
| 5 | 4/1/2004 | 6/30/2006 | 26 | ||||||
| 6 | 9/1/2006 | 4/30/2007 | 7 | ||||||
| 7 | |||||||||
| 8 | 88 | ||||||||
| Formula used in Column F is: =sel2in_cellDateDiff(C7,D7,"m") | |||||||||
| sel2in_cellDateDiff is a custom function defined as | |||||||||
| Public Function sel2in_cellDateDiff(s1 As String, s2 As String, period As String) As Date | |||||||||
| ' function to get the difference of 2 dates in your excel sheet/ workbook | |||||||||
| Dim d1 As Date, d2 As Date | |||||||||
| d1 = DateValue(s1) | |||||||||
| d2 = DateValue(s2) | |||||||||
| sel2in_cellDateDiff = DateDiff(period, d1, d2) | |||||||||
| End Function | |||||||||