My Books

Text Processing with JavaScript

Solve complex text validation, extraction, and modification problems efficiently in JavaScript.

Modern Async JavaScript

Delve into async features of JavaScript from ES2020 through ESNext. Start building custom asynchronous iterators and generators, and more for fast, lean code.

JavaScript Brain Teasers

Ready to test your JavaScript skills? Challenge yourself with these brain-teasing puzzles, supercharge your learning journey, and emerge as a JavaScript pro.

How to Calculate Day from Date in PHP

We are used to arranging our time by the days of the week. People usually use phrases like “next Friday” or “last sunday.” It's easier for us to understand rather than reading a date and having to work out that it means next Friday. In this post, we'll look at how to calculate the day of the week of a given date such as "Apr 25th 1990" in PHP.

Fortunately PHP provides a number of tools such as strtotime() for this purpose. All you have to do is pass the date to the strtotime() function. The strtotime function converts the given date to a Unix timestamp which we can then use with the date function and the l (lowercase L) placeholder to obtain the day of the week. The following code demonstrate how it works:

?php
$timestamp = strtotime("Apr 25th 1990");
$day = date("l", $timestamp);
echo $day; // Wednesday

Have your say