note 49687 added to function.time

From: Date: Fri, 04 Feb 2005 19:45:52 +0000
Subject: note 49687 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-84541@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49687 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49687&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49687&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49687&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49687&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49687&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49687&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84541) next »