Page 1 of 1

Formula for difference in two dates

Posted: Thu Feb 05, 2009 9:04 am
by apsarv
Hi I need a Formula for difference in two dates for the whole column.
The first date is entered in A column and second date in B column and I need the result in C column.
There are around 1000 such entries so it goes from A1 - A1000. So, I was thinking if I can get one formula for the whole column.

ANother problem I am having is that MS Excel formulas are not working in calc.. :o :cry:

I am working in dd/mm/yyyy format

Re: Formula for difference in two dates

Posted: Thu Feb 05, 2009 10:27 am
by Villeroy
=B1-A1 gets the difference between two numbers in unit days. Works in all spreadsheet including Excel.
ANother problem I am having is that MS Excel formulas are not working in calc
Of course 99% of all Excel formulas do work when you simply load your Excel file into Calc.
I am working in dd/mm/yyyy format
Number formats have no influence on the values nor calculations.

Re: Formula for difference in two dates

Posted: Mon Feb 09, 2009 7:38 am
by apsarv
Hi
Thanks for that but I need the formula to get the output in years, months and days.

I use this formula in Excel but its not working in Calc.

=YEAR(A2)-YEAR(A1)-IF(OR(MONTH(A2)<MONTH(A1),AND(MONTH(A2)=MONTH(A1), DAY(A2)<DAY(A1))),1,0)&" years, "&MONTH(A2)-MONTH(A1)+IF(AND(MONTH(A2)<=MONTH(A1),DAY(A2)<DAY(A1)),11,IF(AND(MONTH(A2)<MONTH(A1),DAY(A2)>=DAY(A1)),12,IF(AND(MONTH(A2)>MONTH(A1),DAY(A2)<DAY(A1)),-1)))&" months,"&A2-DATE(YEAR(A2),MONTH(A2)-IF(DAY(A2)<DAY(A1),1,0),DAY(A1))&" days"


and as I need it for the whole column so I thought if I could find a simploer solution than this formula...

Re: Formula for difference in two dates

Posted: Mon Feb 09, 2009 7:53 am
by FJCC
It is too late at night for me to think of another formula, but the one you have seems to work if you change all of the commas to semicolons (except within your literal strings such as "years, ". At least I tried a few variations and the answer was correct.

Re: Formula for difference in two dates

Posted: Mon Feb 09, 2009 9:30 am
by Villeroy
Excel has (undocumented) DATEDIF, in Calc you can use additional functions MONTHS and YEARS.
http://wiki.services.openoffice.org/wik ... y_category

Both applications don't know the respective other application's function, but there are compatible formulas made of common spreadsheet functions:
Re: [Solved] Replacing DATEDIF in an Excel equation? (very similar to your functions).