Win a copy of Head First Android this week in the Android forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

java date

Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to subtract date of previous month which is store in
database from current date to get days because i want that if any record in data base after 15 days from the date when it is inserted should be deleted .we know that date is returned in a we can not subtract it.if we can take differen dd mm yy in ineger through create object of Calendar class.then when we subtract dd mm yy
3 4 2001
29 3 2001

And after all when we get dd mm yy these three integers how to store it and how to insert it to database.
after that when we get current date which is store in string varible then how to subtract this previous date from current date which is stored in a string varible.
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pawan !
Have a look into java.util.Calender and GregorianCalender class. There you can find how to set the calender to a particular date and how to get the date in milliseconds (long).
Get the current date in Milliseconds which is a long (currentlong) .
Get the data-base date in Milliseconds say (databaselong).
differencelong = currentlong - databaselong;
1 Day = 86400 seconds
1 second = 1000 milliseconds
onedaylong = 86400 X 1000;

So divide your result differencelong with onedaylong to get number of days betwen them.
Hope this will help.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic