To get the name of the current month in php, you can use the php date() function and pass “F”.
$month_name = date("F");
echo $month_name;
// Output:
April
If you want to get the current month number, you can use the php idate() function and pass ‘m’.
$month_number = idate('m');
echo $month_number ;
// Output:
4
When working with dates in php, the ability to easily get specific information or format our dates a certain way can be very valuable.
One piece of information which is useful is the month of a date.
We can easily get the current month from a date in php with the php date() function.
If you pass “F” to date, you get the full textual representation of the month of a given date.
Below shows how you can get the month name from a date in php.
$month_name = date('F');
echo $month_name;
// Output:
April
Getting the Current Month Number in php with idate()
There is also a php function which allows you to get the month number of the current month. The php idate() function formats a local time or date as an integer.
With idate(), we can get the current month number as shown below in the following php code.
$month_number = idate('m');
echo $month_number ;
// Output:
4
Hopefully this article has helped you understand how to get the current month in php.