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

Syntax: 
=days360(startdate, enddate, true)

Example:

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

Type the any one of the following in C1 

To find the days difference, use
 =days360(A1,B1,True)
=B1-A1


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

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

Note:
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

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

References:
 http://office.microsoft.com/en-au/excel-help/calculate-the-difference-between-two-dates-HP010070467.aspx

http://www.cpearson.com/excel/datedif.aspx
Post a Comment

Featured Post

Java Introdcution

Please send your review and feedback to psrdotcom@gmail.com