Re: difference between two dates

From: Date: Mon, 16 Oct 2000 16:08:16 +0000
Subject: Re: difference between two dates
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20385@lists.php.net to get a copy of this message
You can also try Date_Calc. This also handles dates pre 1970 or post 2038. http://www.phpinsider.com/php/code/Date_Calc/ require("Calc.php"); $cal = new Date_Calc; echo "number of days between Sep 18, 2000 and Oct 10, 2000 are " .$cal->date_diff("2000","09","18","2000","10","10); vnath@mindspring.com wrote: > > 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 > > -- > 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 -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

« previous php.general (#20385) next »