PHPBuilder - Time left

RSS Twitter
Snippets Calendars Dates

Time left

by: Benjamin Smith
July 26, 2000

Version: 1.0

Type: Function

Category: Calendars/Dates

License: GNU General Public License

Description: returns time left in english when you give seconds. time_left(45) returns "45 seconds." time_left(70) returns "1 minute 10 seconds."

function time_left($integer)
{ /* Returns a string of the amount of time the integer (in seconds) refers


$timeleft='1 day'. 

Will not return anything higher than weeks. False if $integer=0 or fails. 



if ($seconds/60 >=1) 



	if ($minutes/60 >= 1) 

		{ # Hours 


		if ($hours/24 >= 1) 

			{ #days 


			if ($days/7 >=1) 

				{ #weeks 


				if ($weeks>=2) $return="$weeks Weeks"; 

				else $return="$weeks Week"; 

				} #end of weeks 


			if ($weeks>=1 && $days >=1) $return="$return, "; 

			if ($days >=2) $return="$return $days days";

			if ($days ==1) $return="$return $days day";

			} #end of days


		if ($days>=1 && $hours >=1) $return="$return, "; 

		if ($hours >=2) $return="$return $hours hours";

		if ($hours ==1) $return="$return $hours hour";

		} #end of Hours


	if ($hours>=1 && $minutes >=1) $return="$return, "; 

	if ($minutes >=2) $return="$return $minutes minutes";

	if ($minutes ==1) $return="$return $minutes minute";

	} #end of minutes 


if ($minutes>=1 && $seconds >=1) $return="$return, "; 

if ($seconds >=2) $return="$return $seconds seconds";

if ($seconds ==1) $return="$return $seconds second";


return $return; 


Comment and Contribute

Your comment has been submitted and is pending approval.

Benjamin Smith



(Maximum characters: 1200). You have characters left.