Tuesday, February 26, 2013

Excel: Calculate the difference between two dates

Here are some difference date calculations


A2 = "12/3/2012"
A3 = "2/26/2013"


Days between two dates
=A3-A2 = 85

Weekdays between two dates
=Networkdays(A2, A3) = 62

Months between two dates
You could just do Month(A3)-Month(A2) but if you the dates cross different years the result would be incorrect.  Here's the best formula for calculating the # of months between two dates:
= (Year(A3)-Year(A2))*12+Month(A3)-Month(A2) = 2

Years between two dates
=Year(A3)-Year(A2) = 1
This can give you a faulty result.  It hasn't really been 1 year between A3 and A2, but since they are in different years the calculation says 1.


For the same help from Microsoft go to:
http://office.microsoft.com/en-us/excel-help/calculate-the-difference-between-two-dates-HP003056111.aspx

Dates are actually given a sequential number, so A3 = "2/26/2013" is really equal to 41331.  If you see your dates represented by with a number like 41331 you can either change the cell format to "Short Date"(Right click and select "Date" in the format).

Other Date Functions in Excel
DateValue(textvalue)
Let's say you're dealing with an excel file that has a bunch of text that should be a date.  You can use =Datevalue(A2) to convert the text field into a property date field.

Date(Year,Month,Day)
You can also use Date() to build a date field from multiple cells.
Date(Year, Month, Day) is the format.
So if you had A1=2012, B1= 1, and C1 = 1, Date(A1,B1,C1) = "1/1/2012"

Today()
Returns Today's date and will update any time the spreadsheet is opened.

Now()
Returns today's date and timestamp.

Timestamp that doesn't Change
IF you'd like to add the current date in a cell and have it remain fixed just click into a cell, hold the Ctrl key and press the semicolon (;) key.  To insert the crrent time (without a date), press Ctrl-Shift-Semicolon.
This is useful if you want to document your work.  You might want to keep track of when you added new data to your worksheet.


No comments:

Post a Comment