Advertisement
eyuprog

Sample Datediff

May 13th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. <?php
  2. function xTimeAgo ($oldTime, $newTime, $timeType) {
  3.         $timeCalc = strtotime($newTime) - strtotime($oldTime);        
  4.         if ($timeType == "x") {
  5.             if ($timeCalc = 60) {
  6.                 $timeType = "m";
  7.             }
  8.             if ($timeCalc = (60*60)) {
  9.                 $timeType = "h";
  10.             }
  11.             if ($timeCalc = (60*60*24)) {
  12.                 $timeType = "d";
  13.             }
  14.         }
  15.     //detik        
  16.         if ($timeType == "s") {
  17.             $timeCalc .= $timeCalc;
  18.         }
  19.     //menit
  20.         if ($timeType == "m") {
  21.             $timeCalc = round($timeCalc/60);
  22.         }
  23.     //jam      
  24.         if ($timeType == "h") {
  25.             $timeCalc = round($timeCalc/60/60);
  26.         }
  27.     //hari
  28.         if ($timeType == "d") {
  29.             $timeCalc = round($timeCalc/60/60/24);
  30.         }        
  31.         return $timeCalc;
  32.     }
  33. $sekarang=date("Y-m-d H:i:s");
  34. $dulu=date("Y-m-d")." 04:00:00";
  35. $durasi="2";
  36. $diff=xTimeAgo($sekarang,$dulu,"h");
  37. if($diff > $durasi)
  38. {
  39.     echo "LEWAT";
  40. }else{
  41.     echo "BELUM LEWAT";
  42. }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement