aspose file tools*
The moose likes Java in General and the fly likes comparison of dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "comparison of dates" Watch "comparison of dates" New topic
Author

comparison of dates

vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
Hello all,
How to compare two dates in servlets iam using access as database.
vin
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Moved from Servlets to Java In General (Intermediate)


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mattias Ahlin
Greenhorn

Joined: May 31, 2006
Posts: 11
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?


Best regards,<br />Mattias
vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
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

Joined: Aug 16, 2005
Posts: 14269
    
  21

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?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
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.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
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 .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: comparison of dates