note 55722 added to function.date
| From: | ae-dude at mchsi dot com | Date: | Thu, 11 Aug 2005 15:58:46 +0000 |
| Subject: | note 55722 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93448@lists.php.net to get a copy of this message | ||
To calculate how many days old something is is very simple.
<?php
function age($BirthDate, $do)
{
if ($do == "") { $do = "1"; } //Checks if do is set, default set is number of
days
list($month1, $day1, $year1) = split('[-.]', $BirthDate); //Splits date apart
$year = date("Y"); //Gets Current Year
$month = date("m"); //Gets Current Month
$day = date("d"); //Gets Current Day
$date = mktime(0,0,0,$month,$day,$year); //Gets Unix timestamp for current date
$date1 = mktime(0,0,0,$month1,$day1,$year1); //Gets Unix timestamp for date set
$difference = $date-$date1; //Calcuates Difference
$days2 = floor($difference /60/60/24); //Calculates Days Old
//If you choice "2" which is status unstead of days you can modify it here!
if ($days2 <= "20") { $days1 = "2 Weeks"; }
if ($days2 <= "13") { $days1 = "1 Week"; }
if ($days2 <= "7") { $days1 = "New"; }
if ($days2 >= "21") { $days1 = "Old"; }
//End Status Modify
if ($do == "1") { echo $days1; } //Echo Status
if ($do == "2") { echo $days2; } //Echo Days
}
?>
Then just put this where ever you want the days or status to show
age('MM-DD-YYYY', 'S')
Replace MM with the month it was made or born
DD with the day
YYYY with the year
S is what format you want it to show, if you want the days of something such as how many days a post
has been posted enter "2".
If you want status like "New, 1 week, 2 weeks, Old" then enter "1".
Hope you enjoy.
Gordon
FreePgs.com Tech
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55722
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55722&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55722&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55722&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55722&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55722&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55722&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55722&report=yes
Search -- http://master.php.net/manage/user-notes.php