function diff($start,$end = false) {
/*
* For this function, i have used the native functions of PHP. It calculates the difference between two timestamp.
*
* Author: Toine
*
* I provide more details and more function on my website
*/
// Checks $start and $end format (timestamp only for more simplicity and portability)
if(!$end) { $end = time(); }
if(!is_numeric($start) || !is_numeric($end)) { return false; }
// Convert $start and $end into EN format (ISO 8601)
$start = date('Y-m-d H:i:s',$start);
$end = date('Y-m-d H:i:s',$end);
$d_start = new DateTime($start);
$d_end = new DateTime($end);
$diff = $d_start->diff($d_end);
// return all data
$this->year = $diff->format('%y');
$this->month = $diff->format('%m');
$this->day = $diff->format('%d');
$this->hour = $diff->format('%h');
$this->min = $diff->format('%i');
$this->sec = $diff->format('%s');
return true;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.