I have start date and end date.
I need the number of months between this two dates in Java.
For example
- From date: 2009-01-29
- To date: 2009-02-02
It has one jan date and one Feb date.
It should return 2.
I have start date and end date.
I need the number of months between this two dates in Java.
For example
It has one jan date and one Feb date.
It should return 2.
It depends on your definition of a month, but this is what we use:
below logic will fetch you difference in months
Here a complete implementation for monthDiff in java without iterations. It returns the number of full month between two dates. If you want to include the number of incomplete month in the result (as in the initial question), you have to zero out the day, hours, minutes, seconds and millisecondes of the two dates before calling the method, or you could change the method to not compare days, hours, minutes etc.