Advertisement
eyuprog

Diff Date Time

Jan 2nd, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. function xTimeAgo ($oldTime, $newTime, $timeType) {
  2. $timeCalc = strtotime($newTime) - strtotime($oldTime);
  3. if ($timeType == "x") {
  4. if ($timeCalc = 60) {
  5. $timeType = "m";
  6. }
  7. if ($timeCalc = (60*60)) {
  8. $timeType = "h";
  9. }
  10. if ($timeCalc = (60*60*24)) {
  11. $timeType = "d";
  12. }
  13. }
  14. if ($timeType == "s") {
  15. $timeCalc .= " seconds ago";
  16. }
  17. if ($timeType == "m") {
  18. $timeCalc = round($timeCalc/60) . " minutes ago";
  19. }
  20. if ($timeType == "h") {
  21. $timeCalc = round($timeCalc/60/60) . " hours ago";
  22. }
  23. if ($timeType == "d") {
  24. $timeCalc = round($timeCalc/60/60/24) . " days ago";
  25. }
  26. return $timeCalc;
  27. }
  28.  
  29.  
  30. //HOW TO WORK
  31. echo xTimeAgo('2014-01-04 11:40','2014-01-03 11:40',"d");
  32. //results 1 day
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement