-2
I need to compare only the year and month between two dates, I did it the following way and it works perfectly:
$mes1 = "2018/02";
$mes2 = "2018/03";
if($mes1 > $mes2) {
echo "Mês 1 é maior que mês 2";
}elseif($mes2 > $mes1) {
echo "Mês 2 é maior que mês 1";
}
My doubt is about good practice, compare only the year and month so this correct or I would need to use some resource of the php
to say that it is a date? my fear is that start to error in some version of php
future.
NOTE: my doubt is precisely because of the lack of the "day" in this comparison, all the comparisons I saw they have year, month and day, mine does not have the day
I know there are several posts that may look similar to but they are not.
which would cost you to concatenate the day into the variable and make it a date and work correctly with dates in PHP?
– user76097
I don’t need the day, the comparison needs to be only between the months, I need it to try to determine the difference of months that one date has the other
– Otavio Fagundes
I’m not saying you need the day, I’m saying concatenate qq day into variavl to turn it into a date. It might be qq for the two variables. dai compares as date in php
– user76097