Show calendar from custom custom date
<p>Hii i am working on portal which requires calendar from custom dates like from 14 Jul to 14 Aug.I have made a demo which starts properly i.e.if 14th july starts from Thursday but not ending at sunday which is on 14 aug. Take a look what i have done</p>

<pre><code>function getCalender($year = '',$month = '')
{
    $startDate = "2016-07-03";
    $endDate = "2016-07-31";
    $dateYear = ($year != '')?$year:date("Y");
    $dateMonth = ($month != '')?$month:date("m");
    $date = $dateYear.'-'.$dateMonth.'-01';
    $currentMonthFirstDay = date("N",strtotime($date));
    $startDateFrom = date("N",strtotime($startDate));
    $endDateFrom = date("N",strtotime($endDate));
    $timestamp = strtotime($startDate);
    $dayCount = date("d", $timestamp);
    $timestamp1 = strtotime($endDate);
    $dayCountend = date("d", $timestamp1);

    $totalDaysOfMonth = cal_days_in_month(CAL_GREGORIAN,$dateMonth,$dateYear);
    $totalDaysOfMonthDisplay = ($currentMonthFirstDay == 7)?($totalDaysOfMonth):($totalDaysOfMonth + $currentMonthFirstDay);
    //$boxDisplay = ($totalDaysOfMonthDisplay &lt;= 35)?35:42;
    //$boxDisplay = 29

?&gt;


    &lt;div id="calender_section"&gt;
            &lt;h2&gt;
                &lt;!--&lt;a href="javascript:void(0);" onclick="getCalendar('calendar_div','&lt;?php echo date("Y",strtotime($date.' - 1 Month')); ?&gt;','&lt;?php echo date("m",strtotime($date.' - 1 Month')); ?&gt;');"&gt;&amp;lt;&amp;lt;&lt;/a&gt;--&gt;
                &lt;select name="month_dropdown" class="month_dropdown dropdown"&gt;&lt;?php echo getAllMonths($dateMonth); ?&gt;&lt;/select&gt;
                &lt;select name="year_dropdown" class="year_dropdown dropdown"&gt;&lt;?php echo getYearList($dateYear); ?&gt;&lt;/select&gt;
                &lt;!--&lt;a href="javascript:void(0);" onclick="getCalendar('calendar_div','&lt;?php echo date("Y",strtotime($date.' + 1 Month')); ?&gt;','&lt;?php echo date("m",strtotime($date.' + 1 Month')); ?&gt;');"&gt;&amp;gt;&amp;gt;&lt;/a&gt;--&gt;
            &lt;/h2&gt;
            &lt;div id="event_list" class="none"&gt;&lt;/div&gt;
            &lt;!--For Add Event--&gt;
            &lt;div id="event_add" class="none"&gt;
                &lt;p&gt;Add Event on &lt;span id="eventDateView"&gt;&lt;/span&gt;&lt;/p&gt;
                &lt;p&gt;&lt;b&gt;Event Title: &lt;/b&gt;&lt;input type="text" id="eventTitle" value=""/&gt;&lt;/p&gt;
                &lt;input type="hidden" id="eventDate" value=""/&gt;
                &lt;input type="button" id="addEventBtn" value="Add"/&gt;
            &lt;/div&gt;
            &lt;div id="calender_section_top"&gt;
                &lt;ul&gt;
                    &lt;li&gt;Mon&lt;/li&gt;
                    &lt;li&gt;Tue&lt;/li&gt;
                    &lt;li&gt;Wed&lt;/li&gt;
                    &lt;li&gt;Thu&lt;/li&gt;
                    &lt;li&gt;Fri&lt;/li&gt;
                    &lt;li&gt;Sat&lt;/li&gt;
                    &lt;li&gt;Sun&lt;/li&gt;
                &lt;/ul&gt;
            &lt;/div&gt;
            &lt;div id="calender_section_bot"&gt;
                &lt;ul&gt;
                &lt;?php 

                    for($cb=1;$cb&lt;=$dayCountend;$cb++){
                        //echo $cb;
                        if(($cb &gt;= $startDateFrom) &amp;&amp; $cb&lt;=$dayCountend)
                        {
                        /*if(($cb &gt;= $currentMonthFirstDay+1 || $currentMonthFirstDay == 7) &amp;&amp; $cb &lt;= ($totalDaysOfMonthDisplay)){*/
                            //Current date
                            $currentDate = $dateYear.'-'.$dateMonth.'-'.$dayCount;
                            $currentdate = date("D M j",strtotime($currentDate));
                            $eventNum = 0;
                            //Include db configuration file
                            include 'dbConfig.php';
                            //Get number of events based on the current date
                            $result = $db-&gt;query("SELECT title FROM events WHERE date = '".$currentDate."' AND status = 1");
                            $eventNum = $result-&gt;num_rows;
                            //Define date cell color
                            if(strtotime($currentDate) == strtotime(date("Y-m-d"))){
                                echo '&lt;li date="'.$currentDate.'" class="grey date_cell"&gt;';
                            }elseif($eventNum &gt; 0){
                                echo '&lt;li date="'.$currentDate.'" class="light_sky date_cell"&gt;';
                            }else{
                                echo '&lt;li date="'.$currentDate.'" class="date_cell"&gt;';
                            }

                            //Date cell
                            echo '&lt;span&gt;';
                            echo $cb;
                            echo '&lt;/span&gt;';

                            //Hover event popup
                            /*echo '&lt;div id="date_popup_'.$currentDate.'" class="date_popup_wrap none"&gt;';
                            echo '&lt;div class="date_window"&gt;';
                            echo '&lt;div class="popup_event"&gt;Events ('.$eventNum.')&lt;/div&gt;';
                            echo ($eventNum &gt; 0)?'&lt;a href="javascript:;" onclick="getEvents(\''.$currentDate.'\');"&gt;view events&lt;/a&gt;&lt;br/&gt;':'';
                            //For Add Event
                            echo '&lt;a href="javascript:;" onclick="addEvent(\''.$currentDate.'\');"&gt;add event&lt;/a&gt;';
                            echo '&lt;/div&gt;&lt;/div&gt;';

                            echo '&lt;/li&gt;';*/
                            $dayCount++;
                ?&gt;
                &lt;?php }else{ ?&gt;
                    &lt;li&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
                &lt;?php } } ?&gt;
                &lt;/ul&gt;
            &lt;/div&gt;
        &lt;/div&gt;


    &lt;?php
    }
    ?&gt;
</code></pre>