How to get last day of a month from date in PHP ? Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Given a date and the task is to print the last day of the month. We will use date() and strtotime() function to get the last day of the month. Used PHP functions:date() function: Format a local time/date.strtotime() function: Parse about any English textual datetime description into a Unix timestamp.Examples:Input: 2020-04-23Output: ThursdayInput: '2018-09-11'Output: SundayApproach:Given a date stored in a variable as a string, the step is to convert it into date format using strtotime() function.Once we get the date, we will employ date() method. Syntax:date( $format, $timestamp )Within $format, we will pass "Y-m-t" and within $timestamp the date taken above. In terms of date "Y" gives a full numeric representation of a year in 4 digits, "m" provides numeric representation of a month and "t" gives the number of days in the given month.By using "Y-m-t", we will get the number of days in a month because of "t", "m" and "Y" will provide the month and the year.The last step is to use the date() again with "l" for format and the date achieved above as $timestamp. Display the day.Program: php <?php // Given a date in string format $datestring = '2020-04-23'; // Converting string to date $date = strtotime($datestring); // Last date of current month. $lastdate = strtotime(date("Y-m-t", $date )); // Day of the last date $day = date("l", $lastdate); echo $day; ?> OutputThursday Using DateTime ClassIn this approach, we utilize the DateTime class in PHP to get the last day of the month. The DateTime class provides a powerful and flexible way to manipulate and format dates. We can take advantage of its methods to achieve the task efficiently.Example: The following example demonstrates how to use the DateTime class to get the last day of the month and print the day of the week. PHP <?php function getLastDayOfMonth($dateString) { $date = new DateTime($dateString); $date->modify('last day of this month'); $dayOfWeek = $date->format('l'); return $dayOfWeek; } $inputDate1 = '2020-04-23'; echo getLastDayOfMonth($inputDate1); $inputDate2 = '2018-09-11'; ?> OutputThursday Comment V vanshikagoyal43 Follow 0 Improve V vanshikagoyal43 Follow 0 Improve Article Tags : Web Technologies PHP PHP Programs PHP-function Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like