File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes java date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "java date" Watch "java date" New topic

java date

pawan sharma

Joined: Feb 12, 2001
Posts: 7
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.
khudiram Barik

Joined: Feb 12, 2001
Posts: 17
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.
I agree. Here's the link:
subject: java date
It's not a secret anymore!