dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: dates

  1. #1
    Join Date
    Feb 2006
    Posts
    98

    Question dates

    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?

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,137
    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
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Feb 2006
    Posts
    98
    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?

  4. #4
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,137
    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
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  5. #5
    Join Date
    Feb 2006
    Posts
    98
    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?

  6. #6
    Join Date
    Dec 2005
    Posts
    114

    Post example

    Calendar endTime = Calendar.getInstance();

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

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles