Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function xTimeAgo ($oldTime, $newTime, $timeType) {
- $timeCalc = strtotime($newTime) - strtotime($oldTime);
- if ($timeType == "x") {
- if ($timeCalc = 60) {
- $timeType = "m";
- }
- if ($timeCalc = (60*60)) {
- $timeType = "h";
- }
- if ($timeCalc = (60*60*24)) {
- $timeType = "d";
- }
- }
- if ($timeType == "s") {
- $timeCalc .= " seconds ago";
- }
- if ($timeType == "m") {
- $timeCalc = round($timeCalc/60) . " minutes ago";
- }
- if ($timeType == "h") {
- $timeCalc = round($timeCalc/60/60) . " hours ago";
- }
- if ($timeType == "d") {
- $timeCalc = round($timeCalc/60/60/24) . " days ago";
- }
- return $timeCalc;
- }
- //HOW TO WORK
- echo xTimeAgo('2014-01-04 11:40','2014-01-03 11:40',"d");
- //results 1 day
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement