Two Laptop Bag
The moose likes Java in General and the fly likes help me in time comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "help me in time comparison" Watch "help me in time comparison" New topic

help me in time comparison

albert sie
Ranch Hand

Joined: Jan 15, 2006
Posts: 108
i have the code like this

but the current time that i get is in string type and i need to compare the time inside the database which is in time datatype..

how can i solve this problem...
please help me i stuck

JAVA the only can called technology
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

Your code will not compile. What is this line supposed to do?

float time=sdf2;

"but the current time that i get is in string type"

If you do Date d = new Date(); then you have a Date object that contains the time, not a String. You have to get the date out of the database first and then compare it to the current date in Java. Do you know how to get the date out of the database?

Please explain in more detail what you are trying to do, post some more of your code - otherwise it will be hard to help you...

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
debashis ghosh

Joined: Mar 21, 2007
Posts: 4
You must have stored it in Date format in the database if I am not wrong.
And you want to convert the String in your code to date format.
you can do the following:

Date strdate=null;
SimpleDateFormat sdf2= new SimpleDateFormat("");
strdate=sdf2.parse(Your date in String format);

Now that your String has been converted to Date format and stored in strdate,you can compare the two dates.
I agree. Here's the link:
subject: help me in time comparison
It's not a secret anymore!