[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Comparing Java current date to date pulled from database

Posted on 2005-05-03
6
Medium Priority
?
195 Views
Last Modified: 2010-03-31
I want to pull the current date logged on the system and compare it to a date in yyyy-mm-dd format.

I have it all setup and am planning on using the after() method to see if the second date has surpassed the first one.  I just need to get the current date in order for this to work, in the specified format.

Thanks!
0
Comment
Question by:gdlp2004
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 13917251
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String currentDate = sdf.format(new Date());
0
 
LVL 37

Accepted Solution

by:
zzynx earned 720 total points
ID: 13917287
If you want to use after() that's a Date method.

So then
Date currentDate = new Date();

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String databaseDateAsString = "2005-04-15";
Date databaseDate = null;
databaseDate  = sdf.parse(databaseDateAsString);

if (currentDate.after(databaseDate))
   ...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13917288
Date now = new Date();
boolean after = now.after(new java.sql.Date(yourDateString));
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 13917295
Sorry that should have been

Date now = new Date();
boolean after = now.after(java.sql.Date.valueOf(yourDateString));
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13917406
You don't need a DateFormat
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13917444
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month20 days, 5 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question