August 31, 2010

Finding Date Difference in Excel and by using Macro

Date Difference in Excel

We can use Days360 function to find the days difference

=days360(startdate, enddate, true)


A1 B1 C1
3/20/2010 3/26/2010

Type the any one of the following in C1 

To find the days difference, use

To find months difference, use Month(B1)-Month(A1)

To find years difference, use Year(B1)-Year(A1)

Then the sheet A1 and B1 contains the following values with the Date format
A1 B1 C1
3/20/2010 3/26/2010 6

Note: It will return integer value so don't format the resultant(C1) cell to Date.

Date difference by using macro

We can use the datediff function to find the days, months, years difference between two dates

Cell.Value = datediff(interval, Range("startdate_cell").Value, Range("enddate_cell).Value)

interval can be any one of the following
d - days, m - months, y - years, ym - months excluding years, yd - days excluding years, md - days excluding years and months

Range("C1").Value = datediff("d", Range("A1").Value, Range("B1").Value)

Post a Comment

Featured Post

Java Introdcution

Please send your review and feedback to