Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2001092

Re: [PHP] simple question... From: * R&zE: (renze <email protected>)
Date: 09/20/01

<Original message>
From: Ker Ruben Ramos <kreaper <email protected>>
Date: Thu, Sep 20, 2001 at 10:16:01PM -0700
Message-ID: <016101c1425c$819cdcd0$bb05aacb <email protected>>
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 <email protected> -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- ««««««««««««««««««««««««

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>