The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Time Difference
Posted by: Stephen | February 18, 2007 @ 1:06pm
PHP Code
[
Download
]
<?php $h1 = "03"; // Hours $m1 = "45"; // Minutes $s1 = "13"; // Seconds $m1 = "07"; // Month $d1 = "16"; // Day $y1 = "2004"; // Year $date1 = mktime($h1,$m1,$s1,$m1,$d1,$y1); // Returns UNIX timestamp $diff = (time() - $date1); // Difference in seconds between now and then $day = floor($diff/86400); $hour = floor(($diff%86400)/3600); $min = floor(($diff%3600)/60); $sec = ($diff % 60); if ($day == "1") echo "$day day "; elseif ($day > 1) echo "$day days "; if ($hour == "1") echo "$hour hour "; elseif ($hour > 1) echo "$hour hours "; if ($min == "1") echo "$min minute "; elseif ($min > 1) echo "$min minutes "; if ($sec == "1") echo " $sec second "; elseif ($sec > 1) echo " $sec seconds "; echo "ago"; ?>
Syntax Highlighting
[
Open in new window
]
Author Comments
This code will calculate the difference in days, hours, minutes, and seconds between a certain time and now.
Example output: 4 hours 13 minutes 7 seconds
Rating
4.50 / 8
543 Votes