Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Display Time Left To a Date

A PHP function to display the time between now and a future date supplied as Unix time, in human readable format, using two blocks of time periods (year, month, week, day, hour or minute.)

On Friday, July 31st 2009 at 09:30 PM
By Andrew Pociu (View Profile)
*****   (Rated 4.5 with 6 votes)
Contextual Ads
More PHP Resources
Advertisement
  1. function TimeTo($future) // $original should be the future date and time in unix format
  2. {
  3.     // Common time periods as an array of arrays
  4.     $periods = array(
  5.         array(60 * 60 * 24 * 365 , 'year'),
  6.         array(60 * 60 * 24 * 30 , 'month'),
  7.         array(60 * 60 * 24 * 7, 'week'),
  8.         array(60 * 60 * 24 , 'day'),
  9.         array(60 * 60 , 'hour'),
  10.         array(60 , 'minute'),
  11.     );
  12.    
  13.     $today = time();
  14.     $since = $future - $today; // Find the difference of time between now and the future
  15.    
  16.     // Loop around the periods, starting with the biggest
  17.     for ($i = 0, $j = count($periods); $i < $j; $i++)
  18.         {
  19.         $seconds = $periods[$i][0];
  20.         $name = $periods[$i][1];
  21.        
  22.         // Find the biggest whole period
  23.         if (($count = floor($since / $seconds)) != 0)
  24.                 {
  25.             break;
  26.         }
  27.     }
  28.    
  29.     $print = ($count == 1) ? '1 '.$name : "$count {$name}s";
  30.    
  31.     if ($i + 1 < $j)
  32.         {
  33.         // Retrieving the second relevant period
  34.         $seconds2 = $periods[$i + 1][0];
  35.         $name2 = $periods[$i + 1][1];
  36.        
  37.         // Only show it if it's greater than 0
  38.         if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0)
  39.                 {
  40.             $print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
  41.         }
  42.     }
  43.     return $print;
  44. }
  45.  
  46. echo TimeTo(1359101056);
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
by mithusa on Sunday, April 25th 2010 at 02:57 AM

HI WOVA YOU

by mithusa on Sunday, April 25th 2010 at 02:57 AM

HI WOVA YOU

by mithusa on Sunday, April 25th 2010 at 02:57 AM

HI WOVA YOU


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs PHP Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia

Other Resources