Get yesterdays date and if Monday get weekend range

假装没事ソ 提交于 2020-01-02 13:45:16

问题


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)'

回答1:


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())
        );


来源:https://stackoverflow.com/questions/15907162/get-yesterdays-date-and-if-monday-get-weekend-range

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!