PHP - Last day of the month/Number of days in the month

December 2016





Using $m as the number of the month i and $y as year. Function date() can display directly the number of days in the month using the "t" character:


<?
      $month = mktime( 0, 0, 0, $m, 1, $y ); 
      setlocal ('LC_ALL', 'en_EN');
      echo "The month ".date("F Y",$mois)." Has
 ".date("t",$mois)." days";
?>



You can have this value back using :

<? $numberofdays = intval(date("t",$mois)); ?>

Related :

This document entitled « PHP - Last day of the month/Number of days in the month » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.