# Posted By

jkjeldgaard on 01/19/10

# Statistics

Viewed 866 times
Favorited by 0 user(s)

# time between now and future date. (days, hours, minutes, seconds

/ Published in: PHP
Save to your folder(s)

modified version of:
http://www.linein.org/blog/2008/04/04/find-time-between-two-dates-in-php/

Copy this code and paste it in your HTML
`function timeBetweenNowAndDeadline(\$deadline) {	\$currentDate = date("U");	\$diff = \$deadline-\$currentDate;	\$seconds = 0;	\$hours   = 0;	\$minutes = 0; 	if(\$diff % 86400 <= 0){\$days = \$diff / 86400;}  // 86,400 seconds in a day	if(\$diff % 86400 > 0)	{		\$rest = (\$diff % 86400);		\$days = (\$diff - \$rest) / 86400;		if(\$rest % 3600 > 0)		{			\$rest1 = (\$rest % 3600);			\$hours = (\$rest - \$rest1) / 3600;			if(\$rest1 % 60 > 0)			{				\$rest2 = (\$rest1 % 60);			\$minutes = (\$rest1 - \$rest2) / 60;			\$seconds = \$rest2;			}			else{\$minutes = \$rest1 / 60;}		}		else{\$hours = \$rest / 3600;}	} 	if(\$days > 0){\$days = \$days.'d, ';}	else{\$days = false;}	if(\$hours > 0){\$hours = \$hours.'h, ';}	else{\$hours = false;}	if(\$minutes > 0){\$minutes = \$minutes.'m, ';}	else{\$minutes = false;}	\$seconds = \$seconds.'s'; // always be at least one second 	return \$days.''.\$hours.''.\$minutes.''.\$seconds;}`

## Comments

Subscribe to comments

You need to login to post a comment.