0

List of Dates between my From and Two

<?php
$scheduleStartDate = 2015-06-20;
$scheduleEndDate = 2015-06-25;
$Date = getDatesFromRange($scheduleStartDate,$scheduleEndDate);
$Date = substr($Date, 0, -1);
function getDatesFromRange($start, $end){
    $dates = array($start);
    $Value = '';
    while(end($dates) < $end)
    {
        $dates[] = date('Y-m-d', strtotime(end($dates).' +1 day'));
        $Value .= '"'.date('j-n-Y', strtotime(end($dates).' +1 day')).'",';
    }
    return $Value;
}
?>

I'm passing it inside the script that I have , $Date is the one I got from above php file

<script>
        $( window ).load(function() {
        var availableDates = [<?php echo $Date?>];
        function available(date) {
          dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
          if ($.inArray(dmy, availableDates) != -1) {
            return [true, "","Available"];
          } else {
            return [false,"","unAvailable"];
          }
        }

        $('#date').datepicker({ 
            beforeShowDay: available,
            currentText: "Now",
            dateFormat: 'yy-mm-dd',
            inline: true,
            altField: '#datepicker_value', 
            onSelect: function(){
                    getData();
                    }   
        });
        });  
         </script>

Finally I'm enabling the dates in date picker But its enabling 2days late at stat and 1 day extra at the end
Say if I have dates from 20th to 25th it will enable dates from 22nd to 26th
Any help may greatly Appriciated.

Sha
  • 506
  • 2
  • 6
  • 22
  • I think this will help you: http://stackoverflow.com/questions/14851190/date-function-to-display-all-dates-between-two-dates – Vlastislav Novák Jun 17 '15 at 08:26
  • @ Vlastislav Novák No, That post is not helpfully, can post some code how can i achive in my case – Sha Jun 17 '15 at 08:33

1 Answers1

1

Try this PHP code:

<?php
    $scheduleStartDate = '2015-06-20';
    $scheduleEndDate = '2015-06-25';
    $Date = getDatesFromRange($scheduleStartDate, $scheduleEndDate);
    $Date = substr($Date, 0, -1);
    function getDatesFromRange($start, $end){
        $startDate = new DateTime($start);
        $endDate = new DateTime($end);
        $endDate->modify('+1 day');
        $daterange = new DatePeriod($startDate, new DateInterval('P1D'), $endDate);
        $result = '';

        foreach($daterange as $date){
            $result .= '"'.$date->format("j-n-Y").'",';
        }
        return $result;
    }
?>