This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to validate a date greater than current date Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to validate a date greater than current date" Watch "How to validate a date greater than current date" New topic
Author

How to validate a date greater than current date

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
I wanted to validate a date which should not be more than the current date. Any idea as I dont get any clue on this.

I am using the format
DateFormat objDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Eric Bruno
author
Ranch Hand

Joined: Jun 15, 2009
Posts: 60
You can use the Date.compareTo method. It takes an argument Date, and returns the value 0 if the argument Date is equal to this Date; a value less than 0 if this Date is before the Date argument; and a value greater than 0 if this Date is after the Date argument. It's in the Java docs also.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

And if you want date comparison (as in: today, tomorrow etc) just do a search. The question on how to calculate the difference in days between to Date objects has been asked numerous times before.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to validate a date greater than current date
 
Similar Threads
date validation
future date validation
Very Urgent : Fututre Date validation using struts validation
Validator and two fields
Struts2 Problem in validation