Re: difference between two dates

From: Date: Mon, 09 Oct 2000 16:59:36 +0000
Subject: Re: difference between two dates
Groups: php.general 
Request: Send a blank email to php-general+get-19214@lists.php.net to get a copy of this message
Here's a function that should do the trick: function date_diff($from, $to) { list($from_month, $from_day, $from_year) = explode("-", $from); list($to_month, $to_day, $to_year) = explode("-", $to); $from_date = mktime(0,0,0,$from_month,$from_day,$from_year); $to_date = mktime(0,0,0,$to_month,$to_day,$to_year); $days = ($to_date - $from_date)/86400; return $days; } Then just pass the dates to the function like: <?php $days = date_diff("10-1-2000","10-9-2000"); ?> Now $days will hold the number of days between the two dates. Hope this helps! Thanks, Vamsi David Kalosi <kalosi@globtel.sk> wrote: > Hi, all I would like to know if there is any function in PHP that can tell me how many days are from date A till date B. I want create dynamically a list box but I don't know how to get the number between two days. For example date A is 18.09.2000 and date B is 10.10.2000 and I want to know the difference -- Dávid Kálosi Application administrator kalosi@globtel.sk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#19214) next »