Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2009
    Posts
    32
    Rep Power
    0

    Default Adding dates how can i do that

    Hi all
    I want to add dates i am storing date in the format yyyy-mm-dd in my db and want to add 0.6 months or 1.0 years to it how can i do that

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Join Date
    Sep 2009
    Posts
    32
    Rep Power
    0

    Default

    Hi all
    I want to add month in date and store this value to database i have tried this

    accountSubscription.setEnddate(cal.add(Calendar.MO NTH,month);)

    i can not use the following method as it cannot set as Date in db how can i do this pls help
    cal.add(Calendar.MONTH,month);


    Thanks Kirti

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Read the API specs for those methods. The add method returns void, nothing. So you can't pass it's (nonexistent) return value to a method that expects something.
    Better do something like
    Java Code:
    cal.add(Calendar.MONTH, month);
    accountSubscription.setEnddate(cal.getTime());

  5. #5
    Join Date
    Sep 2009
    Posts
    32
    Rep Power
    0

    Default

    But won't this will give time also i only want the date and that to in yyyy-mm-dd format

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Dates don't have a format. If the field set by setEnddate is a a "Date", then this does what you want. How you display that Date is a different discussion.

  7. #7
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Quote Originally Posted by kirtichopra2003 View Post
    But won't this will give time also i only want the date and that to in yyyy-mm-dd format
    You shouldn't worry about formats when storing dates into the database.
    All you do is setTimestamp() and all is done for you. You only worry about formats when presenting the data to users.

  8. #8
    Join Date
    Sep 2009
    Posts
    32
    Rep Power
    0

Similar Threads

  1. Difference of Two Dates
    By jboy in forum New To Java
    Replies: 3
    Last Post: 09-15-2009, 06:41 PM
  2. Help with dates
    By bumblyb33 in forum New To Java
    Replies: 1
    Last Post: 02-13-2009, 02:54 PM
  3. Comparing dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 09:02 AM
  4. help with dates and time
    By osval in forum New To Java
    Replies: 3
    Last Post: 12-12-2007, 12:41 PM
  5. differences between 2 dates
    By cecily in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 05:37 PM

Posting Permissions

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