note 51971 added to function.date

From: Date: Sun, 17 Apr 2005 12:33:56 +0000
Subject: note 51971 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-88109@lists.php.net to get a copy of this message
Here is my code to find date end of last month. <? function days_in_month($month, $year) { // calculate number of days in a month return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31); } function end_of_last_month() { $month = gmstrftime("%m", time () + 25200); $year = gmstrftime("%Y", time () + 25200); if(substr($month,0,1) == "0"){ $month = substr($month,1,1); } $month = intval($month); $year = intval($year); if($month == 1){ $last_month = 12; $year--; } else{ $last_month = $month - 1; } $date = days_in_month($last_month, $year); $eolm = "".$year."-".$last_month."-".$date.""; $ddate = date("d M Y",strtotime($eolm)); return($ddate); } $a = end_of_last_month(); echo $a; ?> ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51971 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51971&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51971&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51971&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51971&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51971&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51971&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88109) next »