Current Location: Home> Latest Articles> How to Determine the Day of the Week for New Year's Day in PHP

How to Determine the Day of the Week for New Year's Day in PHP

gitbox 2025-07-22

Getting the Current Date

In PHP, you can get the current date using the date function, which is one of the most commonly used functions for handling dates and times.

$currentDate = date('Y-m-d');

The code above stores the current date in the format "Year-Month-Day" into the variable $currentDate.

Generating the Date for New Year's Day

New Year's Day is on January 1st each year, so we just need to get the current year and append 01-01 to it.

$newYearDate = date('Y') . '-01-01';

This gives us the full date of New Year's Day for the current year.

Calculating the Weekday of New Year's Day

To find out the exact weekday of New Year's Day, you can use strtotime to convert the date to a timestamp, then combine it with the formatting capability of the date function.

$weekday = date('l', strtotime($newYearDate));

Here, 'l' outputs the full English name of the weekday (such as Monday, Tuesday, etc.).

Outputting the New Year's Day Weekday

The final step is to output the result using the echo function.

echo 'New Year's Day is on: ' . $weekday;

The browser will display something like "New Year's Day is on: Wednesday".

Complete Code Example

Below is the complete PHP code. Copy and run it to see the result:

$currentDate = date('Y-m-d');
$newYearDate = date('Y') . '-01-01';
$weekday = date('l', strtotime($newYearDate));
echo 'New Year's Day is on: ' . $weekday;

Summary

With the code provided in this article, you can easily determine the weekday of New Year's Day each year. The date and strtotime functions in PHP are very useful for handling dates and times, and they are especially helpful for everyday development tasks involving time formatting and conversions.