Here's a handy PHP function I use for comparing times and displaying the difference in a human-readable format.
The function itself returns the nearest approximate time based on the largest value from: decades, years, months, weeks, days, hours, minutes or seconds
<?php
function RelativeTime ( $timestamp ){
$difference = time () - $timestamp ;
$periods = array( "sec" , "min" , "hour" , "day" , "week" , "month" , "years" , "decade" );
$lengths = array( "60" , "60" , "24" , "7" , "4.35" , "12" , "10" );
if ( $difference > 0 ) { // this was in the past
$ending = "ago" ;
} else { // this was in the future
$difference = - $difference ;
$ending = "to go" ;
}
for( $j = 0 ; $difference >= $lengths [ $j ]; $j ++) $difference /= $lengths [ $j ];
$difference = round ( $difference );
if( $difference != 1 ) $periods [ $j ].= "s" ;
$text = " $difference $periods [ $j ] $ending " ;
return $text ;
}
?>
Usage Example
<?php
echo RelativeTime ( $timestamp );
?>
Simple function to return the number of days in a time span between 2 given dates. Categories : PHP , Date Time , MySQL , Databases Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP , Date Time , PHP Classes Calendars to choose a range of dates , reservation events ... Categories : PHP , Calendar , Java Script , Date Time A simple and fast calendar combining PHP and tables. Use this as a base for applications in which a calendar is needed. Categories : Date Time , PHP , Complete Programs , Calendar Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP , Arrays , Date Time , Databases , MySQL Change the background color of a website daily dynamically using the php date function to get the current day of the week and depending on that day, set the background color for the web page. Categories : PHP , Date Time , Beginner Guides , Web Design Customizable Calendar Class Categories : HTML and PHP , Date Time , PHP , PHP Classes , Calendar time() function with microseconds Categories : Date Time , PHP PHP Calendar Web App Categories : PHP , Databases , MySQL , Date Time , Calendar checkdate -- Validate a gregorian date/time Categories : PHP , PHP Functions , Date Time PHP Calendar Categories : PHP , Calendar , Date Time , Java Script , CSS Simple graphic clock/watch generation using gd library. Categories : Graphics , Date Time , PHP Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June). Categories : Calendar , Date Time , PHP formating MySQL Timestamp to get a propper Output.
related : Timestamp, ereg_replace, mysql, substr Categories : MySQL , PHP , Date Time , Databases calculus of the eastersunday Categories : BC math , PHP , Date Time , Databases