Menu

Add Topic

programming

waiting answer July 28, 2021

How to get last day of the current month using PHP - Texinterest.com

Answers
June 13, 2021

Task: Get the last day of the current month.

Used PHP Functions:

  1. date() function in PHP
  2. strtotime() function in PH

Let us see the example

     <?php 
        $date = '2020-04-23';
          
        // Last date of current month.
        $last_date = strtotime(date("Y-m-t", $date ));
          
        // Day of the last date 
        $day_last = date("l", $lastdate);
          
        echo $day_last;
    ?>
0 0
June 13, 2021

Try this if you are using PHP 5.*

     <?php

        $current_date = date('Y-m-d');
        $date = new DateTime($current_date);
        $date->modify('last day of this month');
        echo $date->format('Y-m-d');  
    ?>
0 0
June 13, 2021

$lastday = date('t',strtotime('today'));

0 0
June 13, 2021

 echo date("Y-m-d H:i:s",strtotime("-1 month"))

0 0

Please Login to Post the answer

Leave an Answer