• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Java Current Date time compare

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am getting date from database in format of 2008-03-30 14:20:07.0 and i have stored it in String. I want to compare it with current date time. As i am getting it from DB i cannot change the format.

1) Could you please tell me how to compare it with current date time
2) how to compare 2008-03-30 14:20:07.0 if I convert String to java.util.Date


Thank you for help and time
Ajay
 
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
First of all, why are you getting it from the database as a string? Is it stored as a string in the database, or as a date, time or timestamp type? If it's the latter, you should get it as a java.sql.Date or java.sql.Timestamp:

If there's really no other way then to get it as a string from the database, then you could parse the string into a java.util.Date object using java.text.SimpleDateFormat, and then you can use methods like before() and after() on the Date object to compare it to the current date.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic