Calculate deadlines other than on weekends

Asked

Viewed 892 times

0

I’ll have a system that will have a term of days Ex: 30 days.

I need to calculate a given date within a given deadline, which in case it is a weekend is interpreted as the last working day within the deadline.

Example:

Today: 09-12-2014, Term: 11 days

Should fall in the day 20-12-2014(Saturday), however the system should identify and reduce the deadline to 10 days and inform the final date for the deadline that will be 19-12-2014.

  • 1

    It’s not the full answer but it’s a course to follow :echo date('d/m/Y', strtotime('+5 days', strtotime('14-07-2014'))); sum 5 days from the date of '14-07-2014' to do from today echo date('d/m/Y', strtotime('+5 days'));

  • 1

    For example: $data = today; I have to check if ($date minus 1 day) is Saturday/Sunday or I have to check if $date is Saturday/Sunday?

  • If the final date is Saturday or Sunday I have to make it "give as deadline" the Friday to be working day.

  • Do you then need that given a period of for example 30 days, counting from today, to inform the final date, given that if the final day is a Saturday or Sunday, it is changed to Friday? I couldn’t understand what you needed.

  • I’m seeing something like this: $days = 30; // Input Ex $dataFinal = date('Y-m-d', strtotime("+" . $days . "day", strtotime("now"))); // Here I’ll get the final date + 30 with this I think we can start. Because I will enter in the database the date of Today and also this final Tada and then I make a diff of SQL to try to show the user time of days left. The question now is weekend.

  • About weekend we will see example: Being today’s date 09/12/2014 and more 11 days will fall on 20/12/2014 ie Saturday! With this so I tell the user that the day limit for him to solve THAT, will be day 19/12/2014 by Saturday will not be working day. Check it out? : D

Show 2 more comments

1 answer

1

This method calculates a deadline so that a deadline is not a Saturday or Sunday.

function calcularPrazo($prazoPrevio){
    $dataSTR = date('d-m-Y'); //hoje

    $data = explode('-',$dataSTR);

    //time do dia que sera o dia final do prazo previo
    $time = mktime(0, 0, 0, $data[1], intval($data[0]) + $prazoPrevio, $data[2]);

    $diaSemana = date("w", $time);

    switch($diaSemana){
        case 0: //domingo
            //subtrair mais dois dias
            $prazoPrevio -= 2;
            break;
        case 6: //sabado
            //subtrair mais um dias
            $prazoPrevio -= 1;
            break;
    }

    $time = mktime(0, 0, 0, $data[1], intval($data[0]) + $prazoPrevio, $data[2]);
    return date('d-m-Y',$time);
}
echo calcularPrazo(11);

Example working on Ideone

  • Function is working well, now a future implementation in it of how it would look in the matter of holidays in the week?

  • 1

    I’ll do some research and try to implement this method.

  • 1

    Holidays get complicated, because there are holidays like Carnival that do not have specific days, every year are different dates.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.