whenever you need to subtract a day from the whole date, such as Monday, Tuesday, etc. If you wish to find the day for a given date, such as “2023-7-13,” you can do so in two ways: first, by using strtotime(), and second, by using a DateTime object.
You can see in the example below that I provide you two different ways to determine the day from your date. Now that I have added the format “l,” it will return the entire name of the day, such as “Tuesday,” but if you only want the short name, you may alter the format to “D.”
Example 1:
<?php
$specificDate = strtotime('2023-7-13');
$day = date('l', $specificDate);
var_dump($day);
?>
// Output
string(8) "Thursday"
Example 2:
<?php
$specificDate = strtotime('2023-7-13');
$yourDate = DateTime::createFromFormat("Y-m-d", $specificDate);
var_dump($yourDate->format("l"));
?>
Output:
string(8) "Thursday"
I’m Abhishek, a DevOps, SRE, DevSecOps, and Cloud expert with a passion for sharing knowledge and real-world experiences. I’ve had the opportunity to work with Cotocus and continue to contribute to multiple platforms where I share insights across different domains:
-
DevOps School – Tech blogs and tutorials
-
Holiday Landmark – Travel stories and guides
-
Stocks Mantra – Stock market strategies and tips
-
My Medic Plus – Health and fitness guidance
-
TrueReviewNow – Honest product reviews
-
Wizbrand – SEO and digital tools for businesses
I’m also exploring the fascinating world of Quantum Computing.
[…] https://www.devopsconsulting.in/blog/how-can-i-use-php-to-find-day-name-from-specific-date/ […]