比较和计算变量日期?

使用下面的给定语句,我正在接收varchar中的课程结束日期的值,并且来自MySQL,我试图将其转换为$ced的日期格式,$newformat...一切都很好,但是当我试图将课程结束日期与当前日期进行比较时,它不会进行比较......它只是比较日期,而不是与年份和月份进行比较


 $enddate = $get_students_row['course_end_date'];

 $ced = strtotime("$enddate");

 $newformat = date('d/m/Y',$ced);

 $currentdate = date('d/m/Y');

该函数是,如果$newformat小于和等价到当前日期,则字段变为红色


<tr <?php if(($newformat <= $currentdate)): ?> style="color:red;" <?php endif; ?>>

但它不起作用,除了它使行变红,但它唯一与当前日期不与月份和年份相符...。我也在寻找$newformat总数。


我的代码


                <tr <?php if(($ced <= time())): ?> style="color:red;" <?php endif; ?>>


                   <td><?php  echo $students_rollno_class;?></td>

                   <td><?php  echo $students_admission_no;?> </td>

                   <td><?php  echo $students_firstname;?></td>

                   <td><?php  echo $students_contact;?></td>

                   <td><?php  echo $students_reference_no;?></td>

                   <td><?php  echo date('d/m/Y', strtotime($students_date));?></td>

                   <td><?php  echo $newformat;?></td>




               </tr><?php

                    }

                   ?>


梦里花落0921
浏览 99回答 3
3回答

月关宝盒

您可以看到这种国家格式的比较$format = "d_m_y";$date1&nbsp; = \DateTime::createFromFormat($format, "03_01_12");$date2&nbsp; = \DateTime::createFromFormat($format, "31_12_11");var_dump($date1 > $date2);使用日期时间::创建从格式:

哔哔one

$newformat并且只是 PHP 的简单字符串。比较两个字符串不会给出你期望的答案。因此,最好使用 UNIX 时间格式。$currentdate试试这个:<tr <?php if(($ced <= time())){&nbsp;&nbsp; &nbsp;$totalCount++;&nbsp; &nbsp;echo 'style="color:red;" ';<?php } ?>>我的代码<tr>&nbsp;<tr <?php if(($ced <= time())): ?> style="color:red;" <?php endif; ?>>&nbsp; &nbsp; &nbsp;<td><?php&nbsp; echo $students_rollno_class;?></td>&nbsp; &nbsp; &nbsp;<td><?php&nbsp; echo $students_admission_no;?> </td>&nbsp; &nbsp; &nbsp;<td><?php&nbsp; echo $students_firstname;?></td>&nbsp; &nbsp; &nbsp;<td><?php&nbsp; echo $students_contact;?></td>&nbsp; &nbsp; &nbsp;<td><?php&nbsp; echo $students_reference_no;?></td>&nbsp; &nbsp; &nbsp;<td><?php&nbsp; echo date('d/m/Y', strtotime($students_date));?></td>&nbsp; &nbsp; &nbsp;<td><?php&nbsp; echo $newformat;?></td>&nbsp;</tr><?php } ?>

跃然一笑

$('#timeTable tr td').each(function () {&nbsp; &nbsp; var dtTd = new Date($(this).html());&nbsp; &nbsp; var dtNew = new Date();&nbsp; &nbsp; // 15 minutes is 900000 milliseconds&nbsp; &nbsp;&nbsp; &nbsp; if (dtTd.getTime() - dtNew.getTime() < 900000 && dtNew < dtTd) {&nbsp; &nbsp; &nbsp; &nbsp; $(this).parent('tr').addClass('min15');&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; if (dtNew > dtTd) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(this).parent('tr').addClass('old');&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }});.old {&nbsp; &nbsp; background-color: red;}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><table id="timeTable">&nbsp; &nbsp; <tbody>&nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>02/07/2015 23:15</td>&nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>03/09/2015 11:16</td>&nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>18/02/2020 11:30</td>&nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; </tbody></table>
打开App,查看更多内容
随时随地看视频慕课网APP