note 43891 deleted from function.date by aidan

From: Date: Thu, 08 Jul 2004 00:33:37 +0000
Subject: note 43891 deleted from function.date by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72846@lists.php.net to get a copy of this message
Note Submitter: Christher ---- 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."; ?>

« previous php.notes (#72846) next »