MS Access /强制推迟2个月的日期范围,本周开始(MS Access / forcing a date range 2 months back, bound to this week)

编程入门 行业动态 更新时间:2024-10-27 16:28:35
MS Access /强制推迟2个月的日期范围,本周开始(MS Access / forcing a date range 2 months back, bound to this week)

我有一个查询,我需要,作为日期标准,两个月前结束的一周。

因此,例如,如果我在周一运行查询(截至目前,最后一个星期一是2016年2月1日),它将在2015年11月29日至2015年12月5日(周日至周六)进行查看。

然后下周,如果我运行它,它将集中在2015年12月6日至2015年12月12日(周日至周六)。

但是我需要它返回这个完全相同的日期范围,无论我在哪个工作日运行它。 例如,如果我在2016年2月1日到2016年2月5日(周一至周五)运行它,则会选择2015年11月29日至2015年12月5日的日期范围。

我不确定最好的办法是什么。 我已经考虑过以某种方式试图找到下一个星期六,然后在几周内将其计时,但在dateadd()中似乎没有一周选项。

I have a query where I need, as date criteria, the week ending two months prior.

So for example if I ran the query on Monday (as of right now, the last Monday was 2/1/2016), it would look at 11/29/2015 through 12/5/2015 inclusive (Sunday through Saturday).

And then next week if I ran it, it would focus on 12/6/2015 through 12/12/2015 (Sunday through Saturday).

However I need it to return this exact same date range no matter which weekday of the week I run it. So for example the date range 11/29/2015 through 12/5/2015 would be selected if I ran it on 2/1/2016 through 2/5/2016 (Mon-Fri).

I'm not sure what the best way is to go about this. I've considered somehow trying to find the next Saturday and then clocking that back a few weeks, but there doesn't seem to be a week option in dateadd().

最满意答案

要从周日到周六获得一周的第一个工作日:

FirstWeekDate = DateAdd("d", 1 - Weekday(Date()), Date())

要回去,说8周:

EightWeeksBack = DateAdd("ww", -8, FirstWeekDate)

然后,您可以添加/减去天数以获取间隔,例如。

EightWeeksBackLast = DateAdd("d", 6, DateAdd("ww", -8, FirstWeekDate))

To get the first weekday of a week from Sunday to Saturday:

FirstWeekDate = DateAdd("d", 1 - Weekday(Date()), Date())

To go back, say 8 weeks:

EightWeeksBack = DateAdd("ww", -8, FirstWeekDate)

Then you can just add/subtrack days to get your intervals, for example.

EightWeeksBackLast = DateAdd("d", 6, DateAdd("ww", -8, FirstWeekDate))

更多推荐

本文发布于:2023-07-19 22:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1187991.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:个月   本周   日期   MS   Access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!