Advertisement
arijulianto

PHP Durasi Hari

May 18th, 2014
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.42 KB | None | 0 0
  1. function rentangHari($startDate, $endDate=null){
  2.     $now = $endDate ? strtotime($endDate) : time();
  3.     $begin = strtotime($startDate);
  4.     $datediff = $now - $begin;
  5.     $output = floor($datediff/(60*60*24));
  6.     return $output;
  7. }
  8.  
  9. // contoh 1
  10. $rentang = rentangHari('2014-05-17');
  11. echo $rentang; // output: 2
  12.  
  13. // contoh 2
  14. $tgl1 = '2014-05-17';
  15. $tgl2 = '2014-05-22';
  16. $rentang = rentangHari($tgl1,$tgl2);
  17. echo $rentang; // output: 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement