note 55722 deleted from function.date by derick

From: Date: Sun, 15 Jan 2006 12:43:18 +0000
Subject: note 55722 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-101830@lists.php.net to get a copy of this message
Note Submitter: ae-dude at mchsi dot com ---- 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

« previous php.notes (#101830) next »