aspose file tools*
The moose likes Beginning Java and the fly likes Date manipulation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date manipulation problem" Watch "Date manipulation problem" New topic
Author

Date manipulation problem

Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178


Dear friends,

When i execute this code with the date mentioned above in LINE 1, the program never terminates and goes into an infinite loop. But if i change the date in line 1 to "01/03/2008". The program works perfectly and gives the difference betwee the two dates in months.

Kindly provide your help.
Regards,
Vijay
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
If you start in December of 2007, and keep adding months until you reach March of 2007, of course it's not going to stop. You need to ensure that the start date isn't after the end date.

By the way, I think this

should really be


Ping & DNS - updated with new look and Ping home screen widget
Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178
Dear Ulf,

Thanks for the reply.. But even after changing as you said, the program still goes into an infinite loop if the year is 2007 in Line 1 of the above code.


I changed the equalMonthAndYear as static and made a direct call from checkValidFromDate(). But stil the problem exists.

Please guide me if i had misunderstood anything you had given.

Kindly help me.
Regards,
Vijay
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
Removing the "new Test()" constructor doesn't help with the problem at hand; that was just something I noticed.

You still need to implement the check for the start being after the end date.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

Basically, the problem code is here...



If calc1 doesn't equal calc2, you add a month to calc1 and check again. But what if calc1 is already later than calc2? You can add infinite months to calc1, and it will never equal calc2.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date manipulation problem
 
Similar Threads
Precise age calculation..
Any Alternative for this CODE !!!!!!
Difference Between 2 Dates-Contributed by Hari Krishna Kumar @ Chennai
Date - finding tomorrow
Date difference