简体   繁体   中英

How to get a for-loop list of calendar days in a selected month not to display past months and days

Please i need help on s mall issue i have. I have a for loop that displays all the days of a month with a checkbox to select any day of the month based on the selected month. I need for the list to not display, firstly any month that has passed and for the current month, any day that has passed. Cant figure out the best way to do that within the for loop.

date_default_timezone_set('Africa/Lagos');
        $date = date('Y-m-d H:i:s');

        $cimslots = "25";
        $curyear = date("Y");
        $month = $_POST['month'];
        $day = date('j');
        $daysinmonth = date('t',mktime(0,0,0,$month,1,$curyear));

        <div class="calendarcont">
            <?Php if ($checkday != "Sunday") { ?>
                <div class="calendarheadercont">
                     <div class="calendarday"><?Php echo date("l", mktime(0, 0, 0,$month,$day,$curyear)); ?></div>
                </div>
                <div class="clear_1"></div>
                <div class="calendarsubcont">
                    <div class="calendardatecont">
                        <div class="calendarmonth"><?Php echo date("M", mktime(0,0,0, $month,$day,$curyear)); ?></div>
                        <div class="calendardate"><?Php echo date("j", mktime(0,0,0,$month,$day,$curyear)); ?></div>
                    </div>
                    <div class="calendartextcont">
                        <?Php if ($availableslots > 5){ ?>
                            <div class="calendartextg">Available slots: <?Php echo $availableslots; ?></div>
                        <?php } ?>
                        <?Php if ($availableslots <= 5){ ?>
                           <div class="calendartexto">Available slots: <?Php echo $availableslots; ?></div>
                        <?php } ?>
                        <?Php if ($availableslots == 0){ ?>
                            <div class="calendartextr">No Slots Available!</div>
                        <?php } ?>
                     </div>
                            <?Php if ($availableslots != 0){ ?>
                            <label class="calendarcheckbox">Select
                                <input type="checkbox" name="screening" id="screening" value="<?Php if ($screeningdate=="") {echo date('Y-m-d H:i:s', mktime(0,0,0,$month,$day,$curyear)); }else{ echo $screeningdate; } ?>">
                                <span class="checkmark"></span>
                            </label>
                            <?php } ?>
                        </div>                        
                        <?Php }else if ($checkday == "Sunday"){ ?>
                        <div class="calendarheadercont">
                            <div class="calendarday"><?Php echo date("l", mktime(0, 0, 0,$month,$day,$curyear)); ?></div>
                        </div>
                        <div class="clear_1"></div>
                        <div class="calendarsubcont">
                            <div class="calendardatecont">
                                <div class="calendarmonth"><?Php echo date("M", mktime(0,0,0, $month,$day,$curyear)); ?></div>
                                <div class="calendardate"><?Php echo date("j", mktime(0,0,0,$month,$day,$curyear)); ?></div>
                            </div>
                            <div class="calendartextcont">
                                <div class="calendartextr">Closed On Sundays!</div>
                            </div>
                        </div>
                        <?Php } ?>                                                                  
                    </div>
                <?Php } ?>                   
                </div>

You can return all dates between two dates you specify and put them into array.

You can use date() to specify the start date and set the end date to whatever you want

You can then use this array in your for-loop

Check out this post for a detailed description of how to achieve this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM