info about link
: Javascript : PHP Index : MySQL :
date difference
: Source : : Explanation : : Example : : Todo : : Feedback :

Why this script

I couldn't find an existing function that can calculate the difference between two dates in anything other then an amount of seconds. Translating this into years, months, days, hours, minutes and seconds is more difficult then it seems, since the different months have a different amount of days and you would even have to compensate for leap years. This function will do all that for you though!

Usage

The functions has 2 argument and a third optional one.
   dateDifference($date1, $date2, $output);
The first two arguments are the two dates, the third (optional) one allows you to select the kind of output you want. By default this is a string in the form of x years, x monhts, xdays and x hours, x minutes, xseconds. But it's also possible to have the function return an array; this can be either a normal array (0=>x, 1=>x, 2=>x, etc.), or an associative array ("year"=>x, "month"=>", etc.)

The function will always calculate a positive difference, regardless of the order in which you pass the dates.

The function can also work with flexible ways of writing the dates, due to the usage of the strtotime function
=[Disclaimer]=     © 2005-2010 Excudo.net