GeeCON Prague 2014*
The moose likes JDBC and the fly likes Date Comparison in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Date Comparison in Java" Watch "Date Comparison in Java" New topic
Author

Date Comparison in Java

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732

=======================================================================
operator < cannot be applied to java.lang.String, java.lang.String

if(confirmed==1 && expire_date < today_date){
1 error
=======================================================================

How can I compare two dates?

Thanks & best regards
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Farakh,

How can I compare two dates?


check out after ,before and compareTo
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Well if the Dates are in String format.
Use DateFormat.parse() or SimpleDateFormat.parse() to convert string to Date and then use Date Class method(compareTo).
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Appreciated!

I always got quick answers of my post here at the forum. really love this forum



from my class parsing the parameters like this:


Error:
Can not find symbol
symbol: method paidLogin(java.lang.String)

Please help and correct my code

Thanks again & best regards
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



if(paidLogin(co_id).equals("1"))


Isnt there any method like that paidLogin ? where is it ? is both codes in the same class ?

you are trying to pass the co_id as parameter to get Date from DB . So paidLogin() method should be either in the same class. or access create a object of the class containing paidLogin and call it.

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Sorry the method was not in same folder

but its still have errors

I want to copy paste my whole things to show you. Please guide me as to why its not working?


=======================================================
Output IN WEBPAGE:
Sorry00
=======================================================

OUTPUT IN TOMCAT CONSOLE:
-------------------------
db connected 1
2009-04-20 14:38:12.0
Sun Sep 30 00:00:00 EET 25
Sun Oct 29 00:00:00 EET 24
2009-04-20 14:38:12.0
Sun Sep 30 00:00:00 EET 25
Sun Oct 29 00:00:00 EET 24

Thanks again & best regards
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Farakh,



From SOPs, i get below details.

Here today date as fetched from table = 2009-04-20 14:38:12.0
After df.parse(today_date) - Sun Sep 30 00:00:00 EET 25

The format string (("dd-MM-yyyy") for today Date is wrong , you got to use like ("yyyy-MM-dd hh:mm:ss") for todays date.
But for expire_date , you got to find out what it is being fetched from DB and change the format String as needed.

Currently since Sep 30 is before Oct 29 its true and value od confirmed is not 1 , hence you get login as "0" . Once you have done above change , things should work fine.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39070
    
  23
No longer a beginner's question. Moving. Not sure where would be best, shall try JDBC.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Campbell Ritchie wrote:No longer a beginner's question. Moving. Not sure where would be best, shall try JDBC.


Thanks for your help. I solved the problem in this way:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date Comparison in Java