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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:59:32+00:00 2026-06-09T17:59:32+00:00

I have a startdate, let’s say this is $startDate = 2012-08-01; and I have

  • 0

I have a startdate, let’s say this is $startDate = 2012-08-01; and I have a variable that stores an INT value, lets say this is $value = 10;

I would like to calculate what the date would be from startdate + 10 days and skip weekends.

Using the above values the result would be 2012-08-15

How would this be done?

  • 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-09T17:59:33+00:00Added an answer on June 9, 2026 at 5:59 pm

    This is far from efficient, but who cares about that right when it is readable? 🙂

    <?php
    function calculateNextDate($startDate, $days)
    {
            $dateTime = new DateTime($startDate);
    
            while($days) {
                $dateTime->add(new DateInterval('P1D'));    
    
                if ($dateTime->format('N') < 6) {
                    $days--;
                }
            }
    
            return $dateTime->format('Y-m-d');
    }
    
    echo calculateNextDate('2012-08-01', 10); // return 2012-08-15
    

    DEMO

    What happens should be pretty easy to follow. First we create a new DateTime object using the date provided by the user. After that we are looping through the days we want to add to the date. When we hit a day in the weekend we don’t subtract a day from the days we want to add to the date.

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

Sidebar

Related Questions

I have data from 04/01/2012 00:00 to 05/01/2012 05:00 let say StartDate Value 04/01/2012
Alright, let's say I have a table that looks like this: ID | DATE
I have startdate in QueryString with value: 3/1/2012 DateTime.Parse(Request.QueryString[startdate]).Month return month number: 1 but
I have this <%=Model.StartDate%> <%=Html.Hidden(StartDate, Model.StartDate)%> it outputs: 2010-05-11 11:00:00 +01:00 <input type=hidden value=2010-03-17
Let's say I have a report page that can be customized via Javascript. Say
Let's suppose I have three different select statements, like this SELECT 'Final', ID FROM
Let's consider that I have two date fields. DateTime dt1 = 01/04/2012 DateTime dt2
This is a completely hypothetical question: let's say I have a database where I
i have 2 textboxes that i am filling with StartDate, and Endate. i want
Let's assume that I have the following table: CREATE TABLE [dbo].[PricesHist] ( [Product] [varchar](6)

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.