获取昨天的日期,如果星期一获取周末范围 [英] Get yesterdays date and if Monday get weekend range
问题描述
有没有一种方法可以获取昨天的日期.如果当前日期是星期一,则需要返回三个日期-周日,周六和周五.是否有任何方法可以在单个查询中完成此操作.我对VBA不太了解,但是如果这是解决问题的唯一方法,我愿意弄脏我的手.
Is there a way to get yesterdays date. If the current date is monday I need three dates returned - Sunday, Saturday and Friday. Is there any way possible to accomplish this in a single query. I don't know VBA that well but if that is the only way to solve I am willing to get my hands dirty.
Select * from [Purchase Order] where MyDate = 'Yesterdays date(s)'
推荐答案
WeekDay()
函数将告诉您Date()
函数返回的今天的日期是否为星期一.在IIf()
表达式中使用该表达式,以使MyDate
与昨天不是星期一的昨天的日期匹配,或者MyDate
是星期一的前3个日期匹配.
The WeekDay()
function will tell you whether today's date, as returned by the Date()
function, is Monday. Use that in an IIf()
expression so that MyDate
matches yesterday's date when today is not Monday, or the previous 3 dates when MyDate
is Monday.
SELECT *
FROM [Purchase Order] AS p
WHERE
IIf(Weekday(Date()) = 2,
p.MyDate BETWEEN DateAdd('d',-3,Date())
AND DateAdd('d',-1,Date()),
p.MyDate=DateAdd('d',-1,Date())
);
这篇关于获取昨天的日期,如果星期一获取周末范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!