Posted by Tim on February 12, 2001 1:04 AM
Also-dates ending on the 31st cause the next month to roll to the 1st-such as a date in A3 of May 31 causes a date of July 1st instead of the 30th of June.-thanks
Posted by Celia on February 12, 2001 1:28 AM
Tim
Assuming your date is in A1 and the number of months to be added is in A2 :-
=IF(DAY(EOMONTH(A1,0))=DAY(A1),EOMONTH(EDATE(A1,A2),0),EDATE(A1,A2))
Please note that using this formula to add 1 month (say) to dates of 28,29,30,31 Jan 2001(for example) will all produce a result of 28 Feb 2001.
It could be argued that the difference between 28 Jan and 28 Feb is not 1 month but 1 month and 3 days. Because of the variable days per month, anomalies such as this are unavoidable when calculating date differences.
Celia
Posted by Aladin Akyurek on February 12, 2001 1:34 AM
Try the function EDATE (Look at EDATE under Index (of Contents and Index). It describes how to activate EDATE if not available on your system).
If A2 contains 1-Jan-2001 and you type in A3
=EDATE(A1,1)
you'll get 1-feb-01
If A2 contains 31-Jan-01, the formula will give you 28-Feb-01.
Hope this helps.
Aladin
Posted by Celia on February 12, 2001 1:35 AM
Sorry, I didn't adjust the formula to fit your specific needs.
Put the following in cell A3 and fill down to A17 :-
=IF(DAY(EOMONTH($A$2,0))=DAY($A$2),EOMONTH(EDATE($A$2,ROW()-2),0),EDATE($A$2,ROW()-2))
Celia
Posted by Dave Hawley on February 12, 2001 2:59 AM
EDATE is the one. Just be aware it is part of the Analysis toolpak found under Tools>Add-ins.
Dave
OzGrid Business Applications
Posted by Celia on February 12, 2001 1:53 PM
Yes, except that it doesn't produce the required result if the start date is the last day of a month with less than 31 days. For example, a start date of 28-2-01 will give 28-3-01.
The following works for all month-end dates :-
=IF(DAY(EOMONTH(A1,0))=DAY(A1),EOMONTH(EDATE(A1,1),0),EDATE(A1,1))
Celia
Posted by Aladin Akyurek on February 12, 2001 2:58 PM
What a glitch! I was merely suggesting the function that is needed.
By the way, would a simpler formula not solve the issue?
=EDATE(A1,1)+IF(DAY(A1)=30,1,IF(DAY(A1)=28,3,0))
Aladin
Posted by Celia on February 12, 2001 3:15 PM
Aladin
I don't think your shorter formula will do it since it depends how many months you want to add. For example, if the start date is 28-Feb and you add 2 months, your formula will give a result of 1-May.
Celia
Posted by Dave Hawley on February 12, 2001 5:56 PM
What about =IF(A1=EOMONTH(A1,0),EOMONTH(A1,1),EDATE(A1,1))
OzGrid Business Applications
Posted by Celia on February 12, 2001 11:24 PM
Yes, that's a bit neater.
Celia