Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Get Relative Dates and Times Jump to:  
Category: >> PHP Code >> Get Relative Dates and Times Bookmark and Share

<< lastnext >>

Snippet Name: Get Relative Dates and Times

Description: This function takes seconds as an argument and returns the time difference similar to the Facebook/Twitter does, i.e. "2 minutes ago", "9 hours ago", etc

Also see:
» Get Relative Dates and Times
» Convert Seconds to Hours:Minutes:Secon...
» Calculate the difference between two t...
» Date Functions: Calculate elapsed time...
» Date/Time Calculations: Get seconds be...
» Convert Minutes to Hours
» Convert Hours to Minutes
» Convert 12 to 24 hour time and vice ve...
» Days in month #2
» Days in month #1
» Convert minutes to hours #2
» Convert minutes to hours #1

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

FUNCTION relativedate($secs) {
 
		$second = 1;
		$minute = 60;
		$hour = 60*60;
		$day = 60*60*24;
		$week = 60*60*24*7;
		$month = 60*60*24*7*30;
		$year = 60*60*24*7*30*365;
 
		IF ($secs <= 0) { $output = "now";
		}ELSEIF ($secs > $second && $secs < $minute) { $output = ROUND($secs/$second)." second";
		}ELSEIF ($secs >= $minute && $secs < $hour) { $output = ROUND($secs/$minute)." minute";
		}ELSEIF ($secs >= $hour && $secs < $day) { $output = ROUND($secs/$hour)." hour";
		}ELSEIF ($secs >= $day && $secs < $week) { $output = ROUND($secs/$day)." day";
		}ELSEIF ($secs >= $week && $secs < $month) { $output = ROUND($secs/$week)." week";
		}ELSEIF ($secs >= $month && $secs < $year) { $output = ROUND($secs/$month)." month";
		}ELSEIF ($secs >= $year && $secs < $year*10) { $output = ROUND($secs/$year)." year";
		}ELSE{ $output = " more than a decade ago"; }
 
		IF ($output <> "now"){
			$output = (SUBSTR($output,0,2)<>"1 ") ? $output."s" : $output;
		}
		RETURN $output;
	}
 
 
 
ECHO relativedate(75); // 1 minute, 15 seconds


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 50 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?