day of week function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a function used to determine the Monday of a week given any of the
days in that week? So if today is 12/15/2004, can I use that as a parameter
to return 12/13/2004 without hard-coding =Date()-2?

Thanks,
Melanie
 
Melanie O said:
Is there a function used to determine the Monday of a week given any
of the days in that week? So if today is 12/15/2004, can I use that
as a parameter to return 12/13/2004 without hard-coding =Date()-2?

I believe this will work:

'----- start of function -----
Function MondayDate(pDate As Date) As Date

MondayDate = pDate - Weekday(pDate, vbMonday) + 1

End Function
'----- end of function -----
 
Hi Melanie,

You can use the DatePart function to return the day value of a date
(numbered from 1-7). You should be able to use the result of that function
to subtract back to the previous Monday.

HTH, Ted Allen
 
Is there a function used to determine the Monday of a week given any of the
days in that week? So if today is 12/15/2004, can I use that as a parameter
to return 12/13/2004 without hard-coding =Date()-2?

Weekday([datefield]) does this - by default it returns 1 for Sunday, 2
for Monday and so on. There's an optional argument specifying the
first day of the week.

To get the date of the most recent Monday you could use

DateAdd("d", 1 - Weekday(Date(), 2), Date())

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top