Hello everybody I would like to get the current month of a date.
This is what I tried:
<?php
$transdate = date('m-d-Y', time());
echo $transdate;
$month = date('m', strtotime($transdate));
if ($month == "12") {
echo "<br />December is the month :)";
} else {
echo "<br /> The month is probably not December";
}
?>
But the result is wrong, it should display December is the month :0
Any ideas? thanks.
if($month == 12)
. 12 should be integer not string – Pursuantdate()
returns a string, so you better not wrap 12 in quotes. BTW, when comparing string "12" and interger 12 with==
operator, PHP will ignore data type and regard them as the same.===
operator would be more strict. – Janayjanaya