在查询中使用运算符来使用mySQL在两个日期之间获得差异

时间:2017-11-02 13:57:15

标签: mysql

今天假设是11月2日......

我有这张桌子:

|--------|----------|------------|
| SUB_Id | SUB_Name | SUB_End    |
|--------|----------|------------|
| 1      | Banana   | 2017-11-02 | <- return this row (diff 0 day)
| 2      | Apple    | 2017-11-03 | <- return this row (diff 1 day)
| 3      | Pear     | 2017-11-09 | < don't return this row as diff is > 3
|--------|----------|------------|

我正在使用此查询在SUB_End时获取行 - 今天的日期是&lt; = 3。

SELECT * FROM Subscriptions WHERE SUB_End >= curdate() AND SUB_TrialEnd <= curdate() + interval 15 day

如何从此查询中获得差异?

例如,对于行

1 个答案:

答案 0 :(得分:1)

在mySQL中尝试DateDiff函数。请参阅here