Click to See Complete Forum and Search --> : dates


The One
03-02-2006, 07:28 AM
How do i subtract dates?? See i would like to do it for an employees contact. If the contract expires dat is in the program makes a calculation to take awat the expiry date from the current date and says how long is left. How do i do that?

Khalid Ali
03-02-2006, 09:38 AM
1. create 2 date objects a current date and a contract expiration one.
2. get time in milli seconds from both date objects
3. subtract
4. and convert the remainder to days, months and years etc

read documentation on java.util.Date and java.util.Calendar
at java.sun.com

The One
03-02-2006, 11:51 AM
ok so. this is what i want to do:
u type in the contract expire date in a textfield.
then i want to be able to subtract that from the current date and show that answer .
HOW?

Khalid Ali
03-02-2006, 01:09 PM
get the user input from textfield
textField.getText()l
then convert that to a date by using SimpleDateFormat
now follow the steps in my previous response

The One
03-02-2006, 01:52 PM
wat u mean by simpledateformat? How do u convert it like that?
Do u have an example?

EG:
Contract expiry Date: 05/05/07
Contract left:

How do i get contract left?

Mr. Ram
03-06-2006, 04:03 AM
Calendar endTime = Calendar.getInstance();

// Difference of Time in Minutes AND Conversion Milli-Seconds to Minutes

int diffMins = (int) (( endTime.getTimeInMillis() -
startTime.getTimeInMillis())/(1000*60));