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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:25:47+00:00 2026-05-29T05:25:47+00:00

I’ve been working on a project where a date is calculated based on a

  • 0

I’ve been working on a project where a date is calculated based on a number of days added to current DateTime.Now. I’m using several functions based on this work: business dates calculation , and since this requires a calculation of business days (no weekend days or holidays are calculated, holidays are coded to an app config file), the count needs to start on the current date “now”, or the previous business day if start is on a weekend day or holiday. The current class file always moves ahead to the next business day before starting the count. If the start date is today, the count will start tomorrow.

My requirements for example: a start day of 1/21/2012 is a Saturday. A value of 10 days is added. The resulting date should be February 2. This means the business day to start a calculation is Friday January 20 + 9 more days = 10 days. Another example would be to set the start on Sunday January 22, stepping back to January 20, and add 9 days with the same result. Provided The count does not start on weekends or holidays, it should skip them and arrive at the next calculated business day.

The issue I’m having is my project needs to calculate based on the current date, or step back to the previous business day if the count start is a weekend or holiday.

I think the class file is very clear, but I cant seem to find a way to force the count to start on the current business day, or step backward to the previous business day if the count start is a weekend or holiday.

Please have a look at the code in the link. I’ve attempted to add negative values to the addDays param in several of the existing methods; in my form I’ve tried to force the dateTimePicker value to subtract a day, and a variety of other thrashings about throughout the class file, resulting in failure.

Any advice or help would be greatly appreciated!

Code in button click event:

 //DateTime.Today.AddDays(-4);

         DateTime date = dateTimePicker1.Value;
        // dateTimePicker1.Value.AddDays(-2);
        XDateTime sDate = new XDateTime(dateTimePicker1.Value.ToShortDateString(), XDateTimeType.Business);

        string Str = textBox2.Text.Trim();
        string Str2 = textBox3.Text.Trim();

        double Num;
        bool isNum = double.TryParse(Str, out Num);
        bool isNum2 = double.TryParse(Str2, out Num);
        label6.Text = "";

        //Test whether textBox contains a number or some other character. Fails if not a number.
        if (isNum)
        {
            short days = Convert.ToInt16(textBox2.Text);
            sDate.AddBusinessDays(days);

            lblTodaysDate.Text = " Substantial Completion Date: " + sDate.Date.ToString("MMMM d, yyyy");
            label3.Text = "";

            if (isNum2)
            {
                short days2 = Convert.ToInt16(textBox3.Text);
                sDate.AddBusinessDays(days2);
                label6.Text = " Physical Completion Date: " + sDate.Date.ToString("MMMM d, yyyy");
                label5.Text = "";
            }
            else
                label5.Text = "Please enter numbers only!";             
            return;
        }
        else
           label3.Text = "Please enter numbers only!";
        return;
  • 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-29T05:25:48+00:00Added an answer on May 29, 2026 at 5:25 am

    The modification to the method below results in the count starting on the selected day rather than the next business. This resolves the issue. Thank you to all who commented!

    public void AddBusinessDays(short days)
        {
            double sign = Convert.ToDouble(Math.Sign(days));
            int unsignedDays = Math.Sign(days) * days -1; //*days; added -1 to force count to start on selected day, rather than next business day.
            for (int i = 0; i < unsignedDays; i++)
            {
                do
                {
                    _date = _date.AddDays(sign);
                }
                while (!this.IsWorkDay);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to

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.