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.
php echo 'First Date = ' . date('Y-m-01') . '<br />'; echo 'Last Date = ' . date('Y-m-t') .
MONTH function in Excel - get month number from date For example: =MONTH(A2) - returns the month of a date in cell A2.
$date = strtotime ( $datestring ); // Last date of current month. $day = date ( "l" , $lastdate );
$first_day = date('Y-m-01'); $last_day = date('Y-m-t'); Php Get First Day Of Month. There are a number of different approaches that can be taken to solve the same problem. The following paragraphs will examine the various alternative approaches.
You need to use the default date() function of PHP to get current month. Then you can easily check it by if conditions as mentioned in the code below:
<?php
$month = date('m');
if($month == 12){
echo "<br />December is the month :)";
} else {
echo "<br /> The month is probably not December";
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With