语法以返回给定时间间隔的结果?
我们只是从MySQL切换到Postgres 13.6。
我正在尝试返回从发票创建日期开始30至59天之间的未付发票的结果,因此自创建以来未支付30天和59天的一切。
在MySQL中,这是这样做的:
and datediff(current_date,date(`invoices`.`created_at`)) BETWEEN 30 AND 59;
我尝试了一些不同的事情,之间的 ,但似乎无效。
We just switched from MySQL to Postgres 13.6.
I am trying to return results for unpaid invoices that are between 30 and 59 days from invoice create date, so anything that has gone 30 and 59 days unpaid since being created.
In MySQL this was done as:
and datediff(current_date,date(`invoices`.`created_at`)) BETWEEN 30 AND 59;
I've tried a few different things with intervals and BETWEEN
, but nothing seems to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请确保使用a sargable 表达式
表达式减去整数到日期/从日期开始。示例:
上限和上限的定义是模糊的。不确定您要如何绕上限和下限,并且不确定您是否知道
current_date
取决于当前会话的timezone
设置。我也不相信您的MySQL表达式完全在边缘上做了您想要的...Be sure to use a sargable expression like:
Postgres can add/subtract integer to/from date. Example:
The definition of lower and upper bound are fuzzy. Not sure how you want to round upper and lower bound, and not sure you are aware that
current_date
depends on thetimezone
setting of your current session. I am also not confident your MySQL expression did exactly what you wanted around the edges ...