10-06-2007, 04:56 PM
|
#2 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
I think that the easiest way is to convert the date strings into the integer Unix Timestamp (seconds since 1-1-1970 00:00) using strtotime, subtract one from t'other and there's your difference between the two dates, in seconds.
PHP Code:
$szDateA = '2007-02-12'; $szDataB = '2006-12-25';
// I use abs() here just to make sure the difference is always positive // You can ignore or remove it as you see fit. $iDiffSeconds = abs(strtotime($szDateA) - strtotime($szDateB));
printf('The difference between %s and %s is %d seconds!.', $szDateA, $szDateB, $iDiffSeconds);
After that, you can apply some math to format the output in whatever time scale you like (days, hours, minutes, weeks, whatever).
If you are getting the date strings from MySQL, then there are some schmexy functions which you can plug directly into the query itself to return date differences.
|
|
|
|