PASSWORD RESET

Your destination for complete Tech news

PHP

How to get the name of the Month from the date in PHP?

595 0
< 1 min read

In PHP, you can get the name of the month from a date using the date() function with the “F” format character. Here’s an example:

$dateString = '2023-02-25'; // The date to get the month name from, in YYYY-MM-DD format
$monthName = date('F', strtotime($dateString)); // Get the month name from the date

echo $monthName; // Output: February

In this example, we first convert the date string to a Unix timestamp using the strtotime() function. We then use the date() function with the “F” format character to get the full name of the month. The date() function formats a Unix timestamp into a string representing a date, using the specified format.

The “F” format character outputs the full name of the month (e.g. “January”, “February”, etc.). If you want to output a different format, you can use other format characters. The full list of format characters is available in the PHP documentation for the date() function.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.