Andy2024 Posted Saturday at 12:12 PM Share Posted Saturday at 12:12 PM I have done a calendar at www.suescaravan.co.uk/availability the issue is its showing 2 x July's this is the code $month = '1'; $year = date('Y'); for($m=$month; $m<13; $m++) { $timestamp = mktime(0, 0, 0, $m, 1, $year); $daysInMonth = date("t", $timestamp); $firstDay = date("N", $timestamp); ?> <div class="col-xl-4 col-lg-6" data-aos="fade-up" data-aos-delay="100"> <div class="rounded-3 bg-secondary-subtle"> <h3 class="mb-0 p-2" align="center"><?php echo date('F', mktime(0,0,0,$m)); ?></h3> <table class="table table-bordered m-0" cellspacing="1"> <tr> <th><center>Mon</center></th> <th><center>Tue</center></th> <th><center>Wed</center></th> <th><center>Thu</center></th> <th><center>Fri</center></th> <th><center>Sat</center></th> <th><center>Sun</center></th> </tr> <?php $dayCount = 1; echo "<tr>"; for ($i = 1; $i <= 7; $i++) { if ($i < $firstDay) { echo "<td></td>"; } else { if(strtotime("$year-$m-$dayCount") > strtotime(date('Y-m-d'))) { $bgClass = 'class="table-success btn-date" style="cursor:pointer"'; } else { $bgClass = 'class="table-success"'; } $tdTitle = "Available"; if(!empty($results)){ if( in_array( date('Y-m-d', strtotime("$year-$m-$dayCount")), $booked) ) { $bgClass = 'class="table-danger"'; $tdTitle = "Booked"; } if(in_array( date('Y-m-d', strtotime("$year-$m-$dayCount")), $startDates) ) { $bgClass = 'class="cal-checkin"'; $tdTitle = "Check In"; } if(in_array( date('Y-m-d', strtotime("$year-$m-$dayCount")), $endDates) ) { $bgClass = 'class="cal-checkout btn-date" style="cursor:pointer"'; $tdTitle = "Chesk Out"; } if(in_array( date('Y-m-d', strtotime("$year-$m-$dayCount")), $changeover) ) { $bgClass = 'class="table-danger nice-diagonal"'; $tdTitle = "Change Over"; } } echo "<td $bgClass title='$tdTitle' data-date='".date('d M Y', strtotime("$year-$m-$dayCount"))."' data-rawdate='".date('Y,m,d', strtotime("$year-$m-$dayCount"))."' data-bs-toggle='tooltip' data-bs-placement='top'><center>$dayCount</center></td>"; $dayCount++; } } echo "</tr>"; while ($dayCount <= $daysInMonth) { echo "<tr>"; for ($i = 1; $i <= 7 && $dayCount <= $daysInMonth; $i++) { if(strtotime("$year-$m-$dayCount") > strtotime(date('Y-m-d'))) { $bgClass = 'class="table-success btn-date" style="cursor:pointer"'; } else { $bgClass = 'class="table-success"'; } $tdTitle = "Available"; if(!empty($results)){ if( in_array( date('Y-m-d', strtotime("$year-$m-$dayCount")), $booked) ) { $bgClass = 'class="table-danger"'; $tdTitle = "Booked"; } if(in_array( date('Y-m-d', strtotime("$year-$m-$dayCount")), $startDates) ) { $bgClass = 'class="cal-checkin"'; $tdTitle = "Check In"; } if(in_array( date('Y-m-d', strtotime("$year-$m-$dayCount")), $endDates) ) { $bgClass = 'class="cal-checkout btn-date" style="cursor:pointer"'; $tdTitle = "Chesk Out"; } if(in_array( date('Y-m-d', strtotime("$year-$m-$dayCount")), $changeover) ) { $bgClass = 'class="table-danger checkout"'; $tdTitle = "Change Over"; } } echo "<td $bgClass title='$tdTitle' data-date='".date('d M Y', strtotime("$year-$m-$dayCount"))."' data-rawdate='".date('Y,m,d', strtotime("$year-$m-$dayCount"))."' data-bs-toggle='tooltip' data-bs-placement='top'><center>$dayCount</center></td>"; $dayCount++; } echo "</tr>"; } ?> </table> </div> </div> <?php } ?> Ive tried changing <?php echo date('F', mktime(0,0,0,$m)); ?> to <?php echo date('F', mktime(0,0,0,$m,0,$year)); ?> but its throwing everything out by a month. Does anyone have any idea what is happening? Quote Link to comment https://forums.phpfreaks.com/topic/328164-php-date-glitch/ Share on other sites More sharing options...
Solution Andy2024 Posted Saturday at 12:22 PM Author Solution Share Posted Saturday at 12:22 PM Sorted it, had to change <?php echo date('F', mktime(0,0,0,$m)); ?> to <?php echo date('F', $timestamp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/328164-php-date-glitch/#findComment-1654390 Share on other sites More sharing options...
mac_gyver Posted Saturday at 12:29 PM Share Posted Saturday at 12:29 PM i recommend that you validate the resulting web page at validator.w3.org Quote Link to comment https://forums.phpfreaks.com/topic/328164-php-date-glitch/#findComment-1654392 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.