如何突出显示表中返回'0000-00-00'空日期或无效日期的每个单元格


How to highlight each cell in table that returns '0000-00-00', empty or invalid date?

我试图突出显示从表中返回'0000-00-00',空或无效日期的单元格,但我找不到任何解决方案。请参阅下面的代码

<table class="main_table_med">
                        <tr class="med_tr">
                            <th>Exam Location</th>
                            <th>Exam Date</th>
                        </tr>
                            <tr>
                        <?php
                                while($row = mysql_fetch_array($select)){
                                ?>
                                <td id='ex_date' class="tb_dt"><?php echo $row['exam_date']?></td>
                                <td id='due' class="tb_dt"><?php echo $row['exam_due']?></td>
                            </tr>
                             <?php
                             }  
                            ?>  
                    </table>

你用javascript jquery标记了问题,但它实际上应该是PHP问题,使用PHP检查是否有效日期并相应地显示结果:

<?php
function validateDate($date, $formatExpected = 'Y-m-d H:i:s')
{
  $d = DateTime::createFromFormat($formatExpected, $date);
  return $d && $d->format($formatExpected) == $date
          ? $date
          : 'anyThing';
}
?>
<table class="main_table_med">
                    <tr class="med_tr">
                        <th>Exam Location</th>
                        <th>Exam Date</th>
                    </tr>
                        <tr>
                    <?php
                            while($row = mysql_fetch_array($select)){
                            ?>
                            <td id='ex_date' class="tb_dt"><?php echo validateDate($row['exam_date']) ?></td>
                            <td id='due' class="tb_dt"><?php echo $row['exam_due']?></td>
                        </tr>
                         <?php
                         }  
                        ?>  
                </table>