Such a task is necessary to display the current date before the same date of the next month, that is, for a month in advance. I did something, but I got the feeling that I was bewildered, if there is a better option, please prompt.

enter image description here

<div class="tbody"> <?php if(!empty($users)) : foreach($users as $user) : ?> <div class="tr"> <div class="td"> <div class="wrapp-img"> <img src="/assets/images/photo1.jpg" alt=""> </div> <h4> <?php echo $user['first_name'].' '.$user['second_name']; ?> </h4> <p>Project Manager</p> </div> <?php for($i = 0; $i <= $days_month; $i++) : $day = date('j', strtotime($i.'days')); $dayOfWeek = date('N', strtotime($i.'days')); $weekend = $dayOfWeek == 6 || $dayOfWeek == 7 ? 'holiday-0' : ''; ?> <div class="td <?php echo $weekend; ?>"> <a href='#modal-1' class=' modal-trigger disabled' data-modal="modal-1"> <?php echo $day; ?> </a> </div> <?php endfor; ?> </div> <?php endforeach; endif; ?> </div> 
  • 2
    strtotime ($ i.'days') can be calculated once, and there seems to be no crime. - cheops
  • Thanks for the advice. - quaresma89

2 answers 2

Here I use ... Only for the past month. But the main principle ...

 /** * @param $recordDate * * Возвращает дату прошлого месяца * * @return bool|string */ public static function last_month( $recordDate ) { $date_info = date_parse_from_format( 'Ym-d', $recordDate ); $year = $date_info[ 'year' ]; $month = $date_info[ 'month' ]; $day = $date_info[ 'day' ]; $lastmonth = mktime( 0, 0, 0, $month - 1, $day, $year ); return date( 'Ym-d', $lastmonth ); } 

    if date + month is needed, then date('Ym-d', strtotime('+1 month'))

    • date ('Ymd', strtotime (date (). '+1 month')) apparently so wanted to write? - md5hash