note 94384 added to function.date
| From: | zedar at osu1 dot php dot net | Date: | Sun, 01 Nov 2009 12:54:18 +0000 |
| Subject: | note 94384 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162320@lists.php.net to get a copy of this message | ||
This Function returns the date berfore X days.
you call this function ""daybefore(X)"" X days
<?php
function daybefore($j){
$day = date('d');
$month = date('m');
$year = date('Y');
for ($i=0; $i<$j; $i++) {
if ($day==1) {
if ($month == 1) {
$day = 31;
$month = 12;
$year = $year - 1;
} else {
$month = $month - 1;
switch ($month) {
case 01:
$maxdays=31;
break;
case 02:
$a = $year / 4;
$b = ceil($a);
if ($a==$b){
$maxdays=29;
} else {
$maxdays=28;
}
break;
case 03:
$maxdays=31;
break;
case 04:
$maxdays=30;
break;
case 05:
$maxdays=31;
break;
case 06:
$maxdays=30;
break;
case 07:
$maxdays=31;
break;
case 08:
$maxdays=31;
break;
case 09:
$maxdays=30;
break;
case 10:
$maxdays=31;
break;
case 11:
$maxdays=30;
break;
case 12:
$maxdays=31;
break;
}
$day = $maxdays;
$year = $year;
}
} else {
$day = $day - 1;
$month = $month;
$year = $year;
}}
return "$year-$month-$day";
}
echo daybefore(3);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 92.119.159.27
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/94384
Del: integrated -- https://master.php.net/note/delete/94384/integrated
Del: useless -- https://master.php.net/note/delete/94384/useless
Del: bad code -- https://master.php.net/note/delete/94384/bad+code
Del: spam -- https://master.php.net/note/delete/94384/spam
Del: non-english -- https://master.php.net/note/delete/94384/non-english
Del: in docs -- https://master.php.net/note/delete/94384/in+docs
Del: other reasons-- https://master.php.net/note/delete/94384
Reject -- https://master.php.net/note/reject/94384
Search -- https://master.php.net/manage/user-notes.php