Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetWeekStartDate code won't work

Status
Not open for further replies.

bailey11

Technical User
Jan 18, 2005
103
US
I have a database and I am trying to tell it that the workweek for calculating payroll is Sunday through Saturday.


I wrote the code below, but it won't calculate RT when the week starts over, it just keeps going as if the week didn't end.

Function GetWeekStartDate(DateWorked As Date) As Date
GetWeekStartDate = DateAdd("d", DatePart("w", DateWorked, vbSunday), DateWorked)
End Function

Function GetWeekEndDate(DateWorked As Date) As Date
GetWeekEndDate = DateAdd("d", 6, GetWeekStartDate(DateWorked))
End Function

Thanks in advance for any help.
Bailey11
 
How are ya bailey11 . . .

Is this all dependant on the Current Date?

Calvin.gif
See Ya! . . . . . .
 
So the object, given the current date, is to find the first and last days of the current week? Try this:
Code:
GetWeekStartDate = Date() - WeekDay(Date()) + 1
And...
Code:
GetWeekEndDate = Date() - WeekDay(Date()) + 7
Both snippets assume Sunday is the first day of the week.

And here's a link to some more handy date functions:


HTH,

Ken S.
 
Or using Eupher's code with a mod.
Code:
Function GetWeekStartDate(DateWorked As Date) As Date
    
    GetWeekStartDate = DateWorked - Weekday(DateWorked) + 1
    MsgBox GetWeekStartDate
End Function

Function GetWeekEndDate(DateWorked As Date) As Date
       GetWeekStartDate = DateWorked - Weekday(DateWorked) + 7
End Function
 
I stated it wrong. It is not the current date, it is the date entered on the time sheet. For instance the time sheet starts calculating overtime when an employee hits forty hours. The timekeeper may be entering time for last week's payroll today and it needs to look at what has accumulated for last week to see if the hours are over time yet as eac day for last week is entered.
 
bailey11,
It is not the current date, it is the date entered on the time sheet.
In that case, CaptainD's mod should work.

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top