note 49687 deleted from function.time by aidan

From: Date: Sat, 08 Oct 2005 01:04:02 +0000
Subject: note 49687 deleted from function.time by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96614@lists.php.net to get a copy of this message
Note Submitter: cory^dot^mawhorter^at^gmail^dot^com ---- here are a couple useful functions i wrote <?php /** * Examples * return seconds in a year: * echo time_to_seconds (0, 0, 0, 1); * * get a time() value from 30 days ago: * echo time() - time_to_seconds (0, 0, 30); */ function time_to_seconds ($minutes, $hours=NULL, $days=NULL, $years=NULL) { $seconds = 0; $seconds += $minutes * 60; if ($hours != NULL) $seconds += $hours * 3600; if ($days != NULL) $seconds += $days * 86400; if ($years != NULL) $seconds += $years * 31536000; return $seconds; } /** * This turns time() to an array of values * * Example * print_r (seconds_to_time (time())); * returns * Array ( [years] => 35 * [days] => 43 * [hours] => 19 * [minutes] => 38 * [seconds] => 24 * ) */ function seconds_to_time ($seconds) { $retArr['years'] = floor ($seconds / 31536000); if ($retArr['years'] > 1) $seconds -= $retArr['years'] * 31536000; $retArr['days'] = floor ($seconds / 86400); if ($retArr['days'] > 1) $seconds -= $retArr['days'] * 86400; $retArr['hours'] = floor ($seconds / 3600); if ($retArr['hours'] > 1) $seconds -= $retArr['hours'] * 3600; $retArr['minutes'] = floor ($seconds / 60); if ($retArr['minutes'] > 1) $seconds -= $retArr['minutes'] * 60; $retArr['seconds'] = $seconds; return $retArr; } ?>

« previous php.notes (#96614) next »