如何比较两个日期 [英] how to compare the two date

查看:151
本文介绍了如何比较两个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP前端的MySQL数据库。在我的记录中,我有一个发布日期和到期日期直接从数据库访问。我需要做的是查看是否有任何记录到期日期匹配发布日期。



某些东西:

 <?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']; 
$ exp_date = $ row_Recordset1 ['expire_date'];

if(strtotime($ posted_date)> = strtotime($ exp_date)){
// do whatever
}
/ pre>

假设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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆