note 41557 deleted from function.date by kennyt

From: Date: Sun, 18 Jul 2004 17:22:30 +0000
Subject: note 41557 deleted from function.date by kennyt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73503@lists.php.net to get a copy of this message
Note Submitter: Luis Rodríguez rodriguezlopez1@yahoo.com ---- <?php /*This function return the last month from a date, including months with 31, 30, 29 or 28 days Examples: If you want the last month starting 15/04/2004 this function will return 15/03/2004 If starting 17/12/2003 this function will return 17/11/2003 If starting 14/01/2004 this function will return 14/12/2003 If starting 31/03/2004 this function will return 28/02/2004 If starting 31/07/2004 this function will return 30/06/2004 Example: get_last_month(28,11,2004); */ function get_last_month($day,$month,$year){ if(checkdate($month,$day,$year)): if($month!=1): $last_month = $month-1; $last_year = $year; else: $last_month = 12; $last_year = $year-1; endif; $last_day = $day; while (!checkdate($last_month,$last_day,$last_year)): $last_day--; endwhile; if($last_month<10) $last_month="0".$last_month; if($last_day<10) $last_day="0".$last_day; return $last_day."/".$last_month."/".$last_year; endif; } ?>

« previous php.notes (#73503) next »