Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Start Date should be exactly 1 week before to End Date

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Start Date should be exactly 1 week before to End Date

    Hello all,

    Please clarify below my question:

    In my scenario, End Date is today's date and Start Date should be exactly 1 week before to End Date. Below is the used code:


    Date date = new Date();
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    int i = c.get(Calendar.DAY_OF_WEEK) - c.getFirstDayOfWeek();
    c.add(Calendar.DATE, -i - 7);
    Date startDate = c.getTime();

    return startDate;

    But start date is not updating in this scenario. Kindly help on this issue. Thanks inadvance.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Start Date should be exactly 1 week before to End Date

    Did you try simply? (untested):

    Calendar c = Calendar.getInstance();
    Date endDate = c.getTime();
    c.add( Calendar.DATE, -7 );
    Date startDate = c.getTime();

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    bhanuchandar (December 26th, 2013)

  4. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Start Date should be exactly 1 week before to End Date

    Thanks Greg. It got worked

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Start Date should be exactly 1 week before to End Date

    You're welcome.

Similar Threads

  1. Java Date Format in Date Object
    By Ashr Raza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 13th, 2012, 10:47 AM
  2. Parsing a full date/time/timezone date to "yyyy-MM-dd"
    By Occidentally in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 4th, 2012, 08:57 AM
  3. [SOLVED] getting the end of the month for a given date
    By bczm8703 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 7th, 2011, 04:29 PM
  4. Replies: 1
    Last Post: July 22nd, 2011, 07:08 AM
  5. same date should entered in another date field
    By shashib09 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: July 14th, 2011, 08:42 AM

Tags for this Thread