note 43891 added to function.date
| From: | Christher at rn2 dot php dot net | Date: | Wed, 07 Jul 2004 13:17:58 +0000 |
| Subject: | note 43891 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72827@lists.php.net to get a copy of this message | ||
Here is an function that takes two dates and calculates how many days it's between the dates.
<?
function php_datediff($date1,$date2) {
#Check if date1 and date2 have been set.
if(trim(empty($date1))) {
#Return an message if the startdate is not set.
return "You have not set the start date.";
}
elseif(trim(empty($date2))) {
#Return an message if the enddate is not set.
return "You have not set the end date.";
}
else {
#Split the dates into two arrays.
$d1 = split("-",$date1);
$d2 = split("-",$date2);
#Return the result.
return date("z",mktime(0,0,0,$d2[1],$d2[2],$d2[0]))-
date("z",mktime(0,0,0,$d1[1],$d1[2],$d1[0]));
}
}
?>
Here's an exampel:
<?
echo "It's ".php_datediff(date("Y-m-d"),"2004-08-13")." days
left to the summer olympic games in Athens.";
?>
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43891
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43891&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43891&report=yes
Search -- http://master.php.net/manage/user-notes.php