Calculate date of nearest Thursday

  • Thread starter Thread starter aaron77
  • Start date Start date
A

aaron77

Guest
hi,

i am developing a database in access 2000 and
i need to find a way of getting the date of the nearest
Thursday, using the current date (Date() function)

eg. if i run the this code on friday 06/06/2003, i should be
able to get the date of the nearest thursday which is 12/06/2003.

any thoughts / suggestions would be greatly appreciated
to solve this problem.

regards,

aaron.
 
Code:
Public Function GetThursday(ByVal dteYourDate As Date) As Date

    On Error Goto Err_GetThursday

    Do While WeekDay(dteYourDate) <> 5
        dteYourDate = dteYourDate + 1
    Loop
    
    GetThursday = dteYourDate

Exit_GetThursday:
    Exit Function

Err_GetThursday:
    MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
    Resume Exit_GetThursday

End Function


This function can work for any date you send to it rather than just the current date.
 
Last edited:
try:

Code:
Function NextThursday(d As Variant) As Variant

  NextThursday = d - WeekDay(d) + 5 + IIf(WeekDay(d) < DayCode, 0, 7)
End Function

This function can be used in a query, form or report as:

NextThursday([YourField])
 

Users who are viewing this thread

Back
Top Bottom