Parameters: Do you believe it? This module can be written dozens of times faster than any other method! The parameters are as follows:
1: Which day is the base day?
2: (Optional) What day of the week are you looking for? If not specified, the default value is Saturday
3: (Optional) Should you search forward (past) or backward (future)?
If not specified, the default value is to search in the future (future)
Program code
PublicFunctionSpecificWeekday(ByValDAsDate,OptionalByValWhatDayAsVbDayOfWeek=vbSaturday,OptionalGetNextAsBoolean=True)AsDate
SpecificWeekday=(((D-WhatDay GetNext)/7)-GetNext)*7 WhatDay
EndFunction
Maybe you want to know why the program is written like this?
Did you know? In VB, the base day (0th day) of all date functions is December 30, 1899 (Saturday), and the first day is December 31, 1899 (Sunday), so the WeekDay function algorithm of VB is actually ( Date-1)Mod7 1.
return value
date
Example:
I would like to know which of the following days are they?
Last Monday: SpecificWeekday(Now,vbMonday,False)
Next Saturday: SpecificWeekday(Now)
Next Friday, September 9, 2000: SpecificWeekday("09/09/2000",vbFriday)->