Find date of previous Sunday

bulrush

Registered User.
Local time
Today, 09:55
Joined
Sep 1, 2009
Messages
209
We are paid every week, so this week we are running payroll for last week. Our pay period is Sunday to Saturday. Given today's date, how do I find the date of the just past Sunday?

If I can find the previous Sunday, I can subtract 7 days and get the begin date of the current payroll period we are writing paychecks for.

This must be simple, I just haven't done it before.

Thanks.
 
Hi,

That would work although there might be some other way of doing it:

Public Function LastSunday() As Date
Dim myDate As Date

myDate = Date

While Weekday(myDate, vbSunday) <> vbSunday
myDate = myDate - 1
Wend

LastSunday = myDate

End Function
 
Hi -

Simple one-liner using the DateAdd() function:

Code:
x = date()
? x
9/10/2009 
[B]y = dateadd("d", - weekday(x) +1, x)[/B]
? y
9/6/2009

HTH - Bob
 
Hi -

Simple one-liner using the DateAdd() function:

Code:
x = date()
? x
9/10/2009 
[B]y = dateadd("d", - weekday(x) +1, x)[/B]
? y
9/6/2009

HTH - Bob
Simplicity at its best - I love it when you post things like this Bob! :)
 

Users who are viewing this thread

Back
Top Bottom