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

  • Home
  • SEARCH
  • 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 8149697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:54:15+00:00 2026-06-06T14:54:15+00:00

This is what is my code to print between two dates and it excludes

  • 0

This is what is my code to print between two dates and it excludes the saturday and sunday but this one does not print the last date of the given month.

import org.joda.time.DateTimeConstants;
import org.joda.time.LocalDate;

public class DatesexcludingWeekend {
    public static void main(String[] args) {
        final LocalDate start = new LocalDate(2012, 05, 1);
        final LocalDate end = new LocalDate(2012, 05, 31);
        LocalDate weekday = start;
        if (start.getDayOfWeek() == DateTimeConstants.SATURDAY|| start.getDayOfWeek() == DateTimeConstants.SUNDAY) {
            weekday = weekday.plusWeeks(1).withDayOfWeek(DateTimeConstants.MONDAY);
        }

        while (weekday.isBefore(end)) {
            String dateValues[] = weekday.toString().split("-");
            //System.out.println(dateValues[2]+"/"+dateValues[1]+"/"+dateValues[0]);
            String date=dateValues[2]+"/"+dateValues[1]+"/"+dateValues[0];
            System.out.println("date : "+date);
            if (weekday.getDayOfWeek() == DateTimeConstants.FRIDAY)
                weekday = weekday.plusDays(3);
            else
                weekday = weekday.plusDays(1);
        }
    }
}

Here is the out put of the above code :

date : 01/05/2012
date : 02/05/2012
date : 03/05/2012
date : 04/05/2012
date : 07/05/2012
date : 08/05/2012
date : 09/05/2012
date : 10/05/2012
date : 11/05/2012
date : 14/05/2012
date : 15/05/2012
date : 16/05/2012
date : 17/05/2012
date : 18/05/2012
date : 21/05/2012
date : 22/05/2012
date : 23/05/2012
date : 24/05/2012
date : 25/05/2012
date : 28/05/2012
date : 29/05/2012
date : 30/05/2012

if you see this 31-05/2012 is not getting printed

Please help me to get this solved.

Regards
Tony

  • 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-06-06T14:54:17+00:00Added an answer on June 6, 2026 at 2:54 pm

    It is because you say:

    while (weekday.isBefore(end)) 
    

    If you want to include the last day then two choices:

    1. Set end to one day after the target date (leave while condition as it was)

    2. Change the while condition.

    An alternative while condition would be something like this:

    while (weekday.isBefore(end) || weekday.equals(end)) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code is not pretty, but I want to print out the last generated
Why does this code not print an exception stack trace? public class Playground {
The code below is used to calculate the miles between two cities. In this
I've have a problem trying to print a given period between two dates. Let
I'm trying to get the last Sunday between two week numbers - in order
From this code I don't know the difference between the two methods, collect and
Why does this code would work fine in jQuery 1.5 and not in jQuery
I have written this two .py code to communicate between each outher . A.py
I used this code to print the current page: <form> <input type=button value=Print onClick=window.print();
I'm having a problem with getting this code to print out to file due

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.