Advertisement
arijulianto

PHP Fungsi Ambil Rentang tanggal

Sep 19th, 2014
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. function getDates($sDate, $eDate=NULL){
  2.     $eDate = $eDate ? $eDate : date('Y-m-d');
  3.     $day = 86400;
  4.     if(strtotime($sDate)>strtotime($eDate)){
  5.         $startDate = strtotime($eDate);
  6.         $endDate = strtotime($sDate);
  7.     }else{
  8.         $startDate = strtotime($sDate);
  9.         $endDate = strtotime($eDate);
  10.     }
  11.     $numDays = round(($endDate - $startDate) / $day) + 1;
  12.     $days = array();
  13.     for ($i = 0; $i < $numDays; $i++) {
  14.         $tgl = date($format, ($startDate + ($i * $day)));
  15.         $hari = date('w', ($startDate + ($i * $day)));
  16.         $days[] = $tgl;
  17.     }
  18.     return array_values(array_filter($days));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement