• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Comparison in Java

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

=======================================================================
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Farakh,

How can I compare two dates?


check out after ,before and compareTo
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No longer a beginner's question. Moving. Not sure where would be best, shall try JDBC.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic