Advertisement
arijulianto

Mengambil Data Bulan dari Range

Dec 12th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. function getDates($sDate, $eDate=NULL){
  3.     $tgl_libur = is_array($tgl_libur) ? $tgl_libur : array($tgl_libur);
  4.     $eDate = $eDate ? $eDate : date("Y-m-d");
  5.     $day = 86400;
  6.     if(strtotime($sDate)>strtotime($eDate)){
  7.         $startDate = strtotime($eDate);
  8.         $endDate = strtotime($sDate);
  9.     }else{
  10.         $startDate = strtotime($sDate);
  11.         $endDate = strtotime($eDate);
  12.     }
  13.     $numDays = round(($endDate - $startDate) / $day) + 1;
  14.     $days = array();
  15.     for ($i = 0; $i < $numDays; $i++) {
  16.         $days[] = date("Y-m-d", ($startDate + ($i * $day)));
  17.     }
  18.     return $days;
  19. }
  20.  
  21. $ti1 = $_GET['month_start'];
  22. $ti2 = $_GET['month_end'];
  23. $tgls = getDates($ti1,$ti2);
  24. for($i=0;$i<=count($tgls)-1;$i++)
  25.     $data_bulan[substr($tgls[$i],0,7)] = $i;
  26. $data_bulan = array_keys($data_bulan);
  27. print_r($data_bulan);
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement