Calculate expiration date of the experience contract

3

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

The user types the start date and shows me the date the contract expires in case 45 days or 90 days.

Could anyone give me a tip? Thanks in advance.

    
asked by anonymous 08.09.2016 / 14:20

2 answers

5

With class DateTime , you can do this:

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

As you said the user is going to enter the start date, he will probably enter that date in Portuguese ( d/m/Y ) format.

In this case, I suggest that you Datetime::createFromFormat , to convert the date in Portuguese to a DateTime object.

Do this:

$data_do_input_em_portugues = '10/02/2016';

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

Function strtotime () resolves

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