Applecore Pages on Microsoft Access

Getting the date for a specified day of the week from a given date

If you wish to get the Tuesday of the week for a given date, then you can use a function such as this:

Function fDayOfWeek(dtmDateIn As Date, intWeekDay As Integer) As Date
'   Function to return the date for the named weekday in the same week as the date passed in.
'   Accepts: dtmDateIn - a date
'            intWeekDay - a VBA intrinsic constant, such as vbMonday, or the numeric value (such as 2)
'   Returns: The date of the day in the week.

    fDayOfWeek = IIf(intWeekDay >= WeekDay(dtmDateIn, vbSunday), dtmDateIn + (WeekDay(dtmDateIn, vbSunday) - intWeekDay), dtmDateIn - WeekDay(dtmDateIn, vbSunday) + intWeekDay)
End Function

And then call the function like this:

dtmTuesday=fDayOfWeek(Date,vbTuesday)

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:58:06