Current Location: Home> Latest Articles> Simple Methods to Get the Day of the Week for Today or a Specific Date in PHP

Simple Methods to Get the Day of the Week for Today or a Specific Date in PHP

gitbox 2025-08-02

Common Methods to Get Date and Day of the Week

In PHP, it's straightforward to get the date and the day of the week, primarily using the date() and strtotime() functions.

Introduction to the date() Function

The date() function formats dates and times. Common date formats include:

echo date("Y/m/d"); // Example output: 2022/10/01
echo date("Y-m-d H:i:s"); // Example output: 2022-10-01 10:20:30

To get the current day of the week, use:

echo date("l"); // Outputs full weekday name, e.g., Monday, Tuesday

Introduction to the strtotime() Function

The strtotime() function converts an English textual datetime description into a Unix timestamp, which is useful for further processing. For example:

$date = "2022-10-01"; // Set date
echo date("l", strtotime($date)); // Outputs the corresponding weekday, e.g., Saturday

How to Get the Current Day of the Week

You can get today's weekday directly using date():

$today = date("l"); // Get today's weekday
echo "Today is: " . $today;

Example output: Today is: Saturday

How to Get the Day of the Week for a Specific Date

By parsing a specified date with strtotime() and then using date(), you can get the weekday:

$date = "2022-10-01"; // Specific date
$weekdays = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); // Weekday array
$weekday = $weekdays[date("w", strtotime($date))]; // Get weekday name

echo $date . " is: " . $weekday;

Example output: 2022-10-01 is: Saturday