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 8045709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:37:34+00:00 2026-06-05T05:37:34+00:00

i need to calculate the business days between two dates. ex : we have

  • 0

i need to calculate the business days between two dates.
ex : we have holiday(in USA) on july4th. so if my dates are
date1 = 07/03/2012
date2 = 07/06/2012

no of business days b/w these dates should be 1 since july4th is holiday.

i have a below method to calclulate the business days which will only counts week ends but not holidays.
is there any way to calculate holidays also….please help me on this.

  public static int getWorkingDaysBetweenTwoDates(Date startDate, Date endDate) {  
    Calendar startCal;  
    Calendar endCal;  
    startCal = Calendar.getInstance();  
    startCal.setTime(startDate);  
    endCal = Calendar.getInstance();  
    endCal.setTime(endDate);  
    int workDays = 0;  

    //Return 0 if start and end are the same  
    if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) {  
        return 0;  
    }  

    if (startCal.getTimeInMillis() > endCal.getTimeInMillis()) {  
        startCal.setTime(endDate);  
        endCal.setTime(startDate);  
    }  

    do {  
        startCal.add(Calendar.DAY_OF_MONTH, 1);  
        if (startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY   
       && startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {  
            ++workDays;  
        }  
    } while (startCal.getTimeInMillis() < endCal.getTimeInMillis());  

    return workDays;  
}
  • 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-05T05:37:36+00:00Added an answer on June 5, 2026 at 5:37 am

    Let’s pretend you have a list containing all the holidays, as you mentioned.

    ArrayList<Integer> holidays = ...
    

    Just add a condition to your if condition in your do-while:

    do {
              startCal.add(Calendar.DAY_OF_MONTH, 1);
              if (startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
              && startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY
              && !holidays.contains((Integer) startCal.get(Calendar.DAY_OF_YEAR))) {
                  ++workDays;
              }
    } while (startCal.getTimeInMillis() < endCal.getTimeInMillis());
    

    For simplicity’s sake, I’ve assumed holiday contains dates in the format identical to Calendar.DAY_OF_YEAR.

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

Sidebar

Related Questions

I need to calculate the number of business days between two dates. How can
I need to calculate the DateDiff (hours) between two dates, but only during business-hours
I need to calculate business hours between to dates. I need to exclude following
I need to calculate the number of days passed between 2 dates using java.util.Date,
I need to calculate the time passed between two dates. The catch here is
I need to calculate the distance (in meters and miles) between two coordinates given
I need to calculate the distance between two addresses and I don't need a
I have a table and I need calculate two aggregate functions with different conditions
I need to calculate distance between two locations in my android application. Then I
I need to calculate the within and between run variances from some data as

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.