Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7489085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:11:54+00:00 2026-05-29T15:11:54+00:00

If possible I would prefer a joda or non-joda solution for the scenario below

  • 0

If possible I would prefer a joda or non-joda solution for the scenario below

Lets say if my week starts on 02/05/2012 and the given current date is 02/22/2011. I need to calculate the week start and end date for the given current date. So my solution should have the week start as 02/19 and week ends at 02/25.
For simplicity, I have set my week start here as 02/05/2011 but it could be any day potentially and my week always has 7 days.

My existing code is below but doesnt seem to work as expected.

public Interval getWeekInterval(Date calendarStartDate, Date date)
{
    Calendar sDate = Calendar.getInstance();
    sDate.setTime(getMidnightDate(calendarStartDate));

    Calendar eDate = Calendar.getInstance();
    eDate.setTime(date);

    Calendar weekStartDate = (Calendar) sDate.clone();
    logger.debug("Date:" + sDate.getTime());
    while (sDate.before(eDate)) {
        weekStartDate = sDate;
        sDate.add(Calendar.DAY_OF_WEEK_IN_MONTH, 1);
    }

    return new Interval(weekStartDate.getTime(), sDate.getTime());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:11:54+00:00Added an answer on May 29, 2026 at 3:11 pm

    Try this (pseudo-code):

    // How many days gone after reference date (a known week-start date)
    daysGone  = today - referenceDate;
    
    // A new week starts after each 7 days
    dayOfWeek = daysGone % 7;
    
    // Now, we know today is which day of the week.
    // We can find start & end days of this week with ease
    weekStart = today - dayOfWeek;
    weekEnd   = weekStart + 6;
    

    Now, we can shorten all of this to two lines:

    weekStart = today - ((today - referenceDate) % 7);
    weekEnd   = weekStart + 6;
    

    Note that we subtracted date values like integers to show algorithm. You have to write your java code properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Would prefer not to use javascript if that's possible but a jquery solution
I'm using Hibernate 3.6 but would prefer to stick to JPA annotations if possible.
Any other tweaks for making emacs as vim-like as possible would be appreciated as
Possible Duplicates: How would I implement stackoverflow’s hovering dialogs? i want a small box
Possible Duplicate: How would you count occurences of a string within a string (C#)?
I would like to know if it would be possible to replicate the effect
I was wondering if it would be possible to retrieve the complete list of
I was wondering if it would be possible to do this: $var = '$something
Question So I've recently came up with some new possible projects that would have
Hey, I'm just wondering if it would be possible to convert videos to mp3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.