Robert,

I've been looking at this myself over the past couple of days.

I gather the best approach is to convert your dates into UNIX timestamps. 

For example:

$first_unix_time = mktime($hour1, $minutes1, $seconds1, $month1, $day1, $year1);

$second_unix_time = mktime($hour2, $minutes2, $seconds2, $month2, $day2, $year2);

Subtract the one from the other to give the difference:

$difference = $first_unix_time - $second_unix_time;

The result will be in seconds so you'll need to convert this depending on the format 
you require. 

For example, to convert the difference to years you might do:

$years = floor($difference / (365 * 24 * 60 * 60));

Hope this helps,

Michael Egan

-----Original Message-----
From: ROBERT MCPEAK [mailto:RMCPEAK@;jhuccp.org]
Sent: 12 November 2002 15:31
To: [EMAIL PROTECTED]
Subject: [PHP] newbie: help with date arithmetic[Scanned]


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.


Does somebody have some code handy that does this?  Any help would be greatly 
appreciated!

Thanks.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to