Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

help me in time comparison

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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("hh.mm");
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic