• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

comparison of dates

 
vin Hari
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
How to compare two dates in servlets iam using access as database.
vin
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved from Servlets to Java In General (Intermediate)
 
Mattias Ahlin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you want to compare the dates? Do you want to check if one is befor the other in time, if they are equal or what?
 
vin Hari
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
Thank you for reply ,i want to compare dates means date in a database to current date.
i have written a query like this,
select * from tablename where date<=?
means date till today but this is comparing only days not month and year
please tell me how to do.
vin
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, you have written a query, now what does the rest of your code look like?

What is type the of the column "date" in the table "tablename" in the database?
Are you using a PreparedStatement in your Java code?
If so, then how are you setting the parameter value?
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vin pll:
Hello all,
Thank you for reply ,i want to compare dates means date in a database to current date.
i have written a query like this,
select * from tablename where date<=?
means date till today but this is comparing only days not month and year
please tell me how to do.
vin


I think this pretty much depends on the database you're using. The SQL for Oracle, MySQL and MSSQL varies and they may have their own optimized queries.
 
vin Hari
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
Here iam taking the current date from the textfield and iam writing this in servlet like
req.getParameter(date1);//here date1 is the current date of the text box
it should compare with the database which is having all the dates of pending fees ok then this should compare all the fields of date but here it is comparing only day please modify this

select * from tablename where date<=?//date is a database field name
st.setString(1,date1);
iam using preparestatement only .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic