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 Beginning Java and the fly likes Java date problem 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 » Beginning Java
Reply Bookmark "Java date problem" Watch "Java date problem" New topic
Author

Java date problem

Rus Corina
Ranch Hand

Joined: Jul 08, 2011
Posts: 90
Hello. I have a problem concerning dates in Java and I have no idea what to use. I have a program which deals with contracts. A new contract can be made on at most 2 years. The user must isert date when contract was made (let's call it "initial") and the date when the contract expires (lets call it "final"). My problem is: what can i use in order to verify if the expiration date inserted by the user is smaller or equal to the date when the contract was made +2 years (final<=initial+2 years)?
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

You can use methods of java.util.Date object: before(); after();
Also you can use capabilities of java.util.Calender to scroll over calendar and get the resulting date.

Here's little example:
Rus Corina
Ranch Hand

Joined: Jul 08, 2011
Posts: 90
oh, thank you very much. This should solve my problem. I did not know that you can do that
Rus Corina
Ranch Hand

Joined: Jul 08, 2011
Posts: 90
Actually, doesn't work. I work with both java and sql statements, and when trying to define a Date object, it tells me that it is ambiguous whether it is a java Date object or SQL Date object.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12921
    
    3

Rus Corina wrote:Actually, doesn't work. I work with both java and sql statements, and when trying to define a Date object, it tells me that it is ambiguous whether it is a java Date object or SQL Date object.

Ok, but the reason it doesn't work doesn't have anything to do with the code that Zandis posted.

It's because you have two classes both named Date: java.util.Date and java.sql.Date. If you import both java.util.* and java.sql.* then Java doesn't know which one you mean if you use class Date. You should spell out the entire class name in your code, like this:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
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.
 
subject: Java date problem
 
Similar Threads
how to create a 'diaolg'? bttn that open a new-win ->when closed - rtrn to main form
Does certificate expire?
Paying 20,000$ if i leave job in 1 year.
2 JSpinners with SpinnerModels
Help!!! Insert a new record with a field whose value based on existing records