[英]Ms Access query Where
I am trying to find have to filter my query, in order to show me result from this month and the last month. 我试图查找必须过滤我的查询,以便向我显示本月和上个月的结果。
WHERE t.AllDate Between Date() - 60 and Date()
My code so far is this, but it roll back 60 days. 到目前为止,我的代码是这样,但是它可以回滚60天。
I need to have result for all the last month. 我需要最后一个月的结果。
Thank you. 谢谢。
这样可能更简单:
WHERE DateDiff("m", t.AllDate, Date()) < 2
If the question is 如果问题是
How to get the date of the first day of the previous month ?
如何获得前一个月的第一天的日期?
You can do this in MS Access SQL : 您可以在MS Access SQL中执行此操作:
DateSerial(Year(DateAdd('m',-1,Date())), Month(DateAdd('m',-1,Date())),1)
Right now it returns 1/04/2018
现在它返回
1/04/2018
Your query becomes : 您的查询变为:
WHERE t.AllDate Between DateSerial(Year(DateAdd('m',-1,Date())), Month(DateAdd('m',-1,Date())),1)
and Date()
With this trick you will always get the right year and month, even if you run it in January. 使用此技巧,即使您在一月份运行它,也将始终获得正确的年份和月份。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.