How Can I Use PHP To Find Day Name From Specific Date?

Posted by

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"
0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
1
0
Would love your thoughts, please comment.x
()
x