如何比较两个日期 [英] how to compare the two date
本文介绍了如何比较两个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
某些东西:
<?php $ posted_date = $ row_Recordset1 ['date_posted']; ?>
<?php $ exp_date = $ row_Recordset1 ['expire_date']; ?>
<?php if($ posted_date(Ymd)> = $ exp_date(Ymd)){
//语句
<?php}? >
解决方案
您可以这样做:
$ posted_date = $ row_Recordset1 ['date_posted'];
/ pre>
$ exp_date = $ row_Recordset1 ['expire_date'];
if(strtotime($ posted_date)> = strtotime($ exp_date)){
// do whatever
}
假设DB中的日期是标准的格式日期字符串,这将工作。
I have a MySQL database with a PHP front end. In my records I have a posted date and an expire date directly accessed from the database. What I need to do is check and see if any records expire date matches posted date.
Something like:
<?php $posted_date= $row_Recordset1['date_posted']; ?> <?php $exp_date= $row_Recordset1['expire_date']; ?> <?php if ($posted_date("Y-m-d") >= $exp_date("Y-m-d")) { //statement <?php } ?>
解决方案You could do this:
$posted_date= $row_Recordset1['date_posted']; $exp_date= $row_Recordset1['expire_date']; if (strtotime($posted_date) >= strtotime($exp_date)) { // Do whatever }
This would work assuming that dates from the DB are the standard formated date strings.
这篇关于如何比较两个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文