I have to take out the difference betewen two dates like 1980/10/10 and 2000/05/05.
Could you please tell me that how will i will be able to calculate difference in Months.
Thanks Regards Gaurav
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
The java.text.SimpleDateformat.parse method will convert those strings into Date objects. Then you can use Date.getTime to obtain a millisecond value of both dates. If you then subtract those from each other, and properly divide the result, you will get the number of months in between.
What's the answer for your example? 235? Or 234? Both could be acceptable depending on how you define the problem. So the first thing would be to specify what the question means.
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
Months are not a uniform size, so they are my cutoff in time units. By that I mean hours, minutes, seconds, days, weeks are all meaningful but months are confusing.
For example, what's January 31 + 1 month? What's January 31 + 1 month - 1 month?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Matthew Taylor
Rancher
Joined: Jun 13, 2004
Posts: 110
posted
0
I always translate my GregorianCalendar dates into milliseconds before I do any date calculations. Then you can just subtract to get the difference and do some math to calculate the months.
Grails Consultant
http://dangertree.net
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.