This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes checking for a range of dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "checking for a range of dates" Watch "checking for a range of dates" New topic
Author

checking for a range of dates

Adam Confino
Ranch Hand

Joined: Sep 03, 2009
Posts: 48
Hey Java Gurus! I need help thinking through the programming logic for a method.

Lets say I have a HotelRoom object that has two Strings - CheckIn "Jan-01-10" and CheckOut - "Jan-05-10".
I would like to write a method that could take those two Strings and check for the range of dates.

I'll post the method I have to check for a single date. How would I check for a range?

As always...thanks so much for your valuable time.




Just Another Guy Hooked on Java
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Check the Calendar class.
Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
As an aside, you should create a new SimpleDateFomat an not parse date "one" inside the for loop. The value will remain the same each time so you should move it to the start of the method and reuse the result i.e.



<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
Adam Confino
Ranch Hand

Joined: Sep 03, 2009
Posts: 48
Good catch. Thanks for saving me some frustration!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: checking for a range of dates
 
Similar Threads
Simple operator question
comparing lists
dates, strings, and confusion
NullPointerException
simple date format woes