tags:

views:

35

answers:

1

In Excel 2007, I want to do date difference for the following dates as below:

  A                         B                          C
1 Date1                     Date2                      Difference of A and B
2 2009.11.28 01:25:46:0287  2009.11.28 01:25:46:0287   ?
3 2009.11.28 01:25:46:0443  2009.11.28 01:25:46:0443   ?

Kindly help me with a formula in Excel 2007, to get the difference of the above dates (?).

+2  A: 

Excel stores Dates as a number equal = number of days since 01/01/1900, hence you can just take the difference. i.e.

C2 = A2-B2

Will give you difference in days.

If you want it in seconds, for example, then:

C2 = (A2-B2) * 24 * 60 * 60

If you need to parse the string including the fractions of seconds then:

=DATE(MID(A2,1,4),MID(A2,6,2),MID(A2,9,2))+TIME(MID(A2,12,2),MID(A2,15,2),MID(A2,18,2))+MID(A2,21,4)/(24*60*60*10000)

Will convert A2 into an Excel DateTime. I suggest you put it in cell d2 and copy to e2. C2 can then be based off those.

JDunkerley
I think his problem was with converting the date from a string. (He reposted the question at http://stackoverflow.com/questions/1826017/difference-of-datetimes-ms-excel-2007/1826309#1826309 where he made that statement). Unfortunately I am not aware of a date / time parsing mechanism in Excel that would take the fractional seconds into consideration. Do you know of one?
Richard J Foster
No nice way only the long hand. Will add it to the answer
JDunkerley
It's a very minor point, but it's not exactly days since 01/01/1900, as there is a 'feature' in Excel such that it treats 1900 as a leap year, even though it was not. See here for more information - http://www.joelonsoftware.com/items/2006/06/16.html
Ruffles