Friday, 28 May 2010

Week Ending Function VBA

Just Finished working on a problem for a DB, the client wants all their reporting to be based on Week Ending dates but their files are stored by Date. How can you summarise per week?

I sorted it by creating a function I could then include in my queries -

Public Function WeekEnding(Actual as variant) As Variant
If IsDate(Actual) Then 'Check that variable is a date
WeekEnding = DateAdd("d", Actual, 7-Weekday(Actual)) 'Add on 7 days minus variable day
End If

End Function

No comments:

Post a Comment