Page 1 of 1

### [Solved] Formula to increment month of date field

Posted: Thu Mar 12, 2009 6:54 pm
My problem is determining the formula for incrementing month only of a date field; i.e. 3/20/2009 to 4/20/2009 based on a condition =IF(). Any suggestions?

### Re: Formula to increment month of date field

Posted: Thu Mar 12, 2009 7:40 pm
I think the answer is "it depends". What is the result if you increment the month for the date 2009-03-31? It's not "2009-04-31", so I think you'll need to be a little more precise about what you want, and maybe explain what you want it for.

### Re: Formula to increment month of date field

Posted: Thu Mar 12, 2009 8:02 pm
In developing a worksheet have a cell representing NEXT DUE DATE that is always the 20th day of the month. A1= NEXT DUE DATE. When Today()=NEXT DUE DATE, attempting to increment it one month and replace the NEXT DUE DATE with the incremented value. Was using the conditional format =IF(TODAY()=A1;???;A1). I've not been successful in obtaining the correct result. Hope this helps. New to OpenOffice so any advise is appreciated.

### Re: Formula to increment month of date field

Posted: Thu Mar 12, 2009 8:18 pm
Create a calculated date-series with start value in A1 and constant day 20:
A2: =DATE(YEAR(A1);MONTH(A1)+1;20)
copy down A2

Get next 20th after A1:
=DATE(YEAR(A1);MONTH(A1)+(DAY(A1)>=20);20) [add 1 to the month if the day in A2 >=20]

### Re: Formula to increment month of date field

Posted: Thu Mar 12, 2009 9:37 pm
I tried:
A1= DATE(2009;3;20)
A2=DATE(YEAR(A1);MONTH(A1)+1;20) Resulted error 501
A3=DATE(YEAR(A1);MONTH(A1)+(DAY(A1)>=20);20) Resulted error 501

Used fx DATE to create date series in A1.
Don't understand error results.
Any suggestions what I should try next?

### Re: Formula to increment month of date field

Posted: Thu Mar 12, 2009 11:39 pm
Using Villeroy's formula, I made this example sheet.

Month Increment Test Sheet.ods

### Re: Formula to increment month of date field

Posted: Fri Mar 13, 2009 2:34 am
Thank you Villeroy & Gurhka. Reviewing your test sheet set off a lightbulb-I could easily see what Villeroy meant by copy down A2. Thank you both for helping me understand.
I created my own test sheet & got the same results.

### Re: [Solved] Formula to increment month of date field

Posted: Thu Oct 01, 2009 7:41 pm
A much easier way is the EDATE function which you can feed a date and a number of months after that to return a new date on the same day of the month, just in a different month

### Re: [Solved] Formula to increment month of date field

Posted: Thu Oct 01, 2009 8:09 pm
Interpotential wrote:A much easier way is the EDATE function which you can feed a date and a number of months after that to return a new date on the same day of the month, just in a different month

Yes, EDATE is a little bit easier, but not compatible with Excel. It's not part of the commonly used set of functions. Both, Excel and Calc have EDATE in their "analysis tools".
DATE(y;m;d) is more flexible since it works as "universal date calculator" with any combination of positive or negative numbers for years, months or days. For instance DATE(YEAR(A1);MONTH(A1);0) returns the last day of the preceeding month and it's fairly easy to combine DATE with WEEKDAY to get the first/last Monday...Sunday of some month.

### Re: [Solved] Formula to increment month of date field

Posted: Thu Oct 01, 2009 8:25 pm
Villeroy wrote:... it's fairly easy to combine DATE with WEEKDAY to get the first/last Monday...Sunday of some month.

I'm feeling especially lazy today; how does that work again?

### Re: [Solved] Formula to increment month of date field

Posted: Thu Oct 01, 2009 8:40 pm
acknak wrote:
Villeroy wrote:... it's fairly easy to combine DATE with WEEKDAY to get the first/last Monday...Sunday of some month.

I'm feeling especially lazy today; how does that work again?

It works with mod(weekday;7) and the start of a month.
Any first weekday for any month of any year:
=DATE(myYear;myMonth;1)+MOD(myWeekDay-WEEKDAY(DATE(myYear;myMonth;1));7)
myWeekDay=1 -> Sunday
myWeekDay=7 -> Saturday

Last weekday:
=DATE(myYear;myMonth+1;0)-MOD(WEEKDAY(DATE(myYear;myMonth+1;0))-myWeekDay;7)

### Re: [Solved] Formula to increment month of date field

Posted: Thu Oct 01, 2009 9:11 pm
Of course

I've even used that myself and completely forgotten about it until I saw your example.

Thanks!