3
Hello, I need to test if two dates are equal in PHP (current date x last working day of the month), the two are strings, but I’m not getting the result using the following code:
if(strcmp($ultimo, $hoje) == 0)
echo "<br><br>As duas datas são iguais";
else
echo "<br><br>As duas datas são diferentes";
The calculation for the last working day is as follows::
$mes = 07;
$ano = 2014;
$dias = cal_days_in_month(CAL_GREGORIAN, $mes, $ano);
$ultimo = mktime(0, 0, 0, $mes, $dias, $ano);
$dia = date("j", $ultimo);
$dia_semana = date("w", $ultimo);
if($dia_semana == 0){
$dia--;
$dia--;
}
if($dia_semana == 6)
$dia--;
$ultimo = (string)mktime(0, 0, 0, $mes, $dia, $ano);
For the current date:
$hoje= date("d/m/Y");
The two dates show the result 31/07/2014, but I’m not getting equality in the result. If anyone can help.
The variable
$ultimo
is not in the format with which you are comparing.– Beterraba