How to show month name in PHP?
PHP has a date function that we can use to show the date. The PHP date() function can take different types of format and display date depending on that format.
Using the date() function, we can also show the month name in PHP.
Show month name in PHP using date() function
To show the month name on the web page using the date function, we just have to pass a particular format inside the function. To show the full month name we have to pass “F” as the format inside that function just like you can see below:
The above PHP code will give the current month name:
Also, we can show the short textual representation of a month which is consist of three letters by passing the “M” format just like you can see below:
It will show the short name of the month:
We can also display month name with date, year and other parameters together. Below are some of the examples of using various date parameter format:
<?php echo date('F d, Y'); echo "<br/>"; echo date('dS M, l'); echo "<br/>"; echo date('dS M Y'); ?>
We will see the output for the above code that is given below:
December 13, 2018 13th Dec, Thursday 13th Dec 2018
So, you have seen how we can show month name in PHP using the date() function. We have also seen that how we can use that name within date, year, day name.
I hope, this post will be helpful to you. If you have any question related to this post, you can ask me.