Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 32
Registered: ‎10-21-2012
My Device: 9900
My Carrier: NA
Accepted Solution

Add One Month to Date

How Do I add one month to a date? DateTimeUtilities.ONEMONTH only adds 4 weeks.  How do I add for instance one month to Jan 1, 2012 to make it Feb 1, 2012 (not Jan 29, 2012)?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Add One Month to Date

The only way I know to do this is to put the date into a Calendar Object as you have done here:

http://supportforums.blackberry.com/t5/Java-Development/String-Date-Between-Dates/m-p/1977725#M21126...

then extract the month, add 1, and put it back, unless the result is > 11, in which case you need to reset the month to 0 and add 1 to the year.

Contributor
Posts: 12
Registered: ‎10-31-2012
My Device: 9320, developer
My Carrier: Telus

Re: Add One Month to Date

You may need to consider month-days like 29, 30, and 31 separately. For example, adding 1 month to January 30, 2012- should that be February 28 (1 day less than end of month), February 29, or March 1?

 

You can store the true day of month separately and return either the end of month day (if the month is shorter) or the true selected day. This would allow you to add 1 month, every month, and always come up with the closest day to the desired day. For example, incrementing 1 month at a time, you would see Jan 30, Feb 29, Mar 30...

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Add One Month to Date

Jolly good point, kudos to you....