0

我的 sql 查询有一点问题。

在数据库中,我有发票的到期日。

保存为字符串 12-01-2013

现在我想将此日期与今天进行比较。但不工作。

这是解码。

include_once('config/connect.php');

连接数据库();

$name = $_GET['name'];

$date = date('d-m-Y');

$qry = "SELECT *, finished_invoice.date AS invoice_date FROM finished_invoice
    INNER JOIN customer 
    ON finished_invoice.customer = customer.customer_nr 
        WHERE finished_invoice.user = '".$_SESSION['id']."' 
    AND customer.company_name = '$name'
    AND expiry_date < '$date'
    AND finished_invoice.sent > '0'
    AND finished_invoice.paid = '0'   
    ORDER BY finished_invoice.id DESC"

如果有人可以帮助我。

谢谢。

4

2 回答 2

0

而不是比较日期对象使用 strtotime() 函数来比较为字符串

于 2013-01-06T16:00:59.777 回答
0

您正在将 PHP 日期格式 dmy 与 mysql 格式 ymd 进行比较,这就是您遇到问题的原因。
尝试使用这个:

   SELECT *, finished_invoice.date AS invoice_date FROM finished_invoice
        INNER JOIN customer 
        ON finished_invoice.customer = customer.customer_nr 
            WHERE finished_invoice.user = '".$_SESSION['id']."' 
        AND customer.company_name = '$name'
        AND expiry_date < STR_TO_DATE($date, '%d-%m-%Y')
        AND finished_invoice.sent > '0'
        AND finished_invoice.paid = '0'   
        ORDER BY finished_invoice.id DESC
于 2013-01-06T16:43:49.580 回答