At 16:30 12.11.2002, ROBERT MCPEAK spoke out and said:
--------------------[snip]--------------------
>I'm trying to add/subract two dates.  I think I need to use mktime() but I 
>can't quite figure out how.
>
>I'd like to do something like this:
>
>(2002-11-15)-(2002-11-10)=5
>
>or
>
>(2002-12-10)-(2002-11-10)=20
>
>Obviously taking into account number of days in a given month.
--------------------[snip]-------------------- 

:)) rtfm, again :))

1) http://www.php.net/manual/en/function.strtotime.php
2) http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html

3) your second equation would return 30, not 20 ;->
4) try this:

/* untested */
function days($str_from, $str_to) {
    $from = strtotime(isset($str_from) ? $str_from : 'now');
    $to   = strtotime(isset($str_to) ? $str_to : 'now');
    if ($from > $to) {
       $x = $from; $from = $to; $to = $x;
    }
    $rslt = $to - $from;         // number in seconds
    return (int)($rslt / 86400); // return days (1d = 86400 secs)
}
    
Hope this helps,

-- 
   >O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
    ^ http://www.vogelsinger.at/

Reply via email to