dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 24, 1998

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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 If
End Function
Serge Natanov
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date