4
Guys I need to put together a code on php
where I enter 2 dates and it returns the difference in months. Example:
$data1 = "2016-03-01";
$data2 = "2016-06-10";
Resultado 3 meses
Example 2:
$data1 = "2015-06-01";
$data2 = "2016-06-10";
Resultado 12 meses
Solved as follows: $monthsAhead = $range->m + ($range->y * 12);
not and not duplicated, that’s a very different situation.
– Hugo Borges
But you can use the same answer as the previous question, because both calculate
– Sr. André Baill
@Hugoborges This is it ->
$intervalo = $firstDate->diff($lastDate);
– celsomtrindade
I posted a solution
– Sr. André Baill
eu Tenez thus: $dateInterval = $data_inicio->diff($data_fim); echo $dateInterval->m; however it ignores the year, ie if I put '2016-06-01' and 2015-06-01' it returns me 0, and the correct would be 12
– Hugo Borges
@Hugoborges do not put the answer to the question. Add your own answer in the answers section ;)
– celsomtrindade