devxlogo

Determine Next/Previous Weekday

Determine Next/Previous Weekday

This function returns week identifier information, such as Week Beginning/Ending date, and makes it more generic to return a date of any previous or following weekday. You can use this function in VB5 and VBA5; with minor modifications to the optional arguments, you can also use it in VB3 and VB4:

 Public Function SpecificWeekday(d As Date, _	Optional ByVal WhatDay As Byte = _	vbSaturday, Optional ByVal GetNext _	As Boolean = True) As Date	'Purpose: Returns a date of the 	'Next/Previous specific weekday for a given date	' Input:		d - Date for which next/previous 	'			weekday is needed 	'			WhatDay - optional (byte) 	'			argument (default = vbSaturday)	'			specifying what weekday to find	'			GetNext - optional (Boolean) 	'			argument: True for 	'			Next(default), False for Previous	'Output:		Date of the next/previous specific weekday	'Note:		If both optional arguments are 	'			omitted, returns Week-Ending Date	'			If passed date (d) falls on the 	'			same weekday as WhatDay, the 	'			function returns the passed date 	'			unchanged.	Dim iAdd As Integer	iAdd = (WhatDay - WeekDay(d))	If GetNext Then		SpecificWeekday = DateAdd("d", IIf(_			iAdd >= 0, iAdd, 7 + iAdd), d)	Else		SpecificWeekday = DateAdd("d", IIf(_			iAdd <= 0, iAdd, iAdd - 7), d)	End IfEnd Function
See also  5 Ways to Improve Customer Experience
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist