How To Get Last Day Of Month From Date In PHP?

03-Apr-2023

.

Admin

How To Get Last Day Of Month From Date In PHP?

Hello Dev,

This article will give you example of get last day of month from date in php. I explained simply about get last day of month from date in php. This tutorial will give you simple example of get last day of month in PHP. You'll learn get last day of month date in PHP.

In this post, i will show you get last day of month from date in php.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.

So let's see bellow solution:

Example:


<?php

// Given a date in string format

$getDate = '2022-01-03';

// Converting string to date

$date = strtotime($getDate);

// Last date of current month.

$lastGetDate = strtotime(date("Y-m-t", $date ));

// Day of the last date

$day = date("l", $lastGetDate);

echo $day;

?>

Output:

Monday

I hope it will help you....

#PHP