Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Date Comparison in Java

 
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
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • 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 VI Editor Java
  • 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 VI Editor Java
  • 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 VI Editor Java
  • 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.
 
Marshal
Posts: 69395
276
  • 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:
 
Good night. Drive safely. Here's a tiny ad for the road:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic