I need to pull info based on a date field, where if today is Monday, pull anything from the prior Friday, Sat or Sun, otherwise pull just yesterday. Is there a way to do this?
Public Function PrevWorkingDay(InDate As Date) As Date
Dim CurrentDay As Integer
CurrentDay = Weekday(InDate, vbSaturday)
If CurrentDay <= 3 Then
PrevWorkingDay = DateAdd("d", -1 * CurrentDay, InDate)
Else
PrevWorkingDay = DateAdd("d", -1, InDate)
End If
End Function
Incidentally, a lot of people put unnecessary complexity in date and time arithmetic. Dates are stored as numbers of days so you can just add/subtract the days. DateAdd is good for things like months where the number of days varies.
This was very helpful! I've been trying to figure out how to do this forever! Now I have another question...How do I get this date to show on my report header?
Thanks!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.