Re: simple question...

From: Date: Thu, 20 Sep 2001 14:42:51 +0000
Subject: Re: simple question...
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-67997@lists.php.net to get a copy of this message
<Original message> From: Ker Ruben Ramos <kreaper@iligan.mine.nu> Date: Thu, Sep 20, 2001 at 10:16:01PM -0700 Message-ID: <016101c1425c$819cdcd0$bb05aacb@weblinqproxy> Subject: Re: [PHP] simple question... > again.. one more thing.... How do I know how many days date differ? let's > say '2001-09-01' and '2001-09-08'. > Just looking for the fastest way of code to run. </Original message> <Reply> The sample code below does pretty much what you want. BUT!!! It's not a very nice solution... Eg it cannot calculate a difference of more than one year :( Furthermore I must point out that there is no error-checking in this example. So if you _do_ want to use this, you'll have to add the error-checking. Sorry that it's not a really good solution, but due to lack of time, I could not think of anything better right now... --- PHP Example Code --- <PRE> <?php $dateOne = "2001-09-01"; $dateTwo = "2001-09-08"; ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $dateOne, $match_1); ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $dateTwo, $match_2); $stampOne = mktime (0,0,0,$match_1[2],$match_1[3],$match_1[1]); $stampTwo = mktime (0,0,0,$match_2[2],$match_2[3],$match_2[1]); $days_differ = date("z", ($stampTwo-$stampOne)); print ("Days: $days_differ"); ?> </PRE> --- End of PHP Example Code --- </Reply> -- * R&zE: -- »»»»»»»»»»»»»»»»»»»»»»»» -- Renze Munnik -- DataLink BV -- -- E: renze@datalink.nl -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- ««««««««««««««««««««««««

« previous php.general (#67997) next »