简体   繁体   English

如何在date_trunc中添加整数变量

[英]How add integer variable in the date_trunc

I want to add my i variable in the date_trunc. 我想在date_trunc中添加我的i变量。 My i variable has value 10. This is a piece of my code : 我的i变量的值为10。这是我的一部分代码:

date_trunc('month', now()) - interval 'i  month'

error: 错误:

pq: invalid input syntax for type interval: "i  month"

您可以使用算术:

date_trunc('month', now()) - i * interval '1  month'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM