PASSWORD RESET

Your destination for complete Tech news

PHP

How to get the name of the day from a date in PHP?

441 0
< 1 min read

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

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

echo $dayName; // Output: Saturday

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 “l” format character to get the full name of the day of the week. The date() function formats a Unix timestamp into a string representing a date, using the specified format.

The “l” format character outputs the full name of the day of the week (e.g. “Sunday”, “Monday”, 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.