Calculate the maturity date of the experience contract

Asked

Viewed 1,061 times

3

I need to create a screen that automatically calculates the expiration dates of the experience contract.

The user enters the initial date and already shows me the date that wins the contract in case 45 days or 90 days.

Could someone give me a hint? Thanks in advance.

  • 45 working days or 45 calendar days?

  • 45 straight days

  • If the answer was helpful, you can mark one of them, young man.

2 answers

5

Function strtotime() resolves

$vencimento = strtotime("+45 day");
echo date("Y/m/d", $vencimento);

5


With class DateTime, you can do so:

$vencimento = (new Datetime())->modify('+45 days');

As you said that the user will enter the initial date, he will probably type this date in Portuguese format (d/m/Y).

In that case, I suggest you Datetime::createFromFormat, to convert the date in English to an object DateTime.

Do it that way:

$data_do_input_em_portugues = '10/02/2016';

$vencimento = DateTime::createFromFormat('d/m/Y', $data_do_input_em_portugues)
                     ->modify('+45 days');

Browser other questions tagged

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