note 41557 added to function.date
| From: | "LuisRodr�guezrodriguezlopez1" at yahoo dot com | Date: | Wed, 14 Apr 2004 16:12:49 +0000 |
| Subject: | note 41557 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68125@lists.php.net to get a copy of this message | ||
<?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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41557
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41557&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41557&report=yes
Search -- http://master.php.net/manage/user-notes.php