Week Ending

  • Thread starter Thread starter csgraham74
  • Start date Start date
C

csgraham74

Hi Guys,

I was wondering if anyone could help me find a function to get a week
ending function??

i.e. week ending on sunday

Therefore if a i was to input todays date in my function it would
output the sunday date of the same week. If anyone has a such a
function or can point me in the right direction it would be most
helpful.

Regards

CG
 
You can use the 'DayOfWeek' Property of the Date type to figure out the day
of today


Today.DayOfWeek will return an enum value that you can calculates the next
Sunday based on that

hth,
Samuel Shulman
 
Use the DayOfWeek property to determine the current day, convert it to
an integer, and use it to calculate how many days you have to add to get
to the end of the week.

E.g. if Wednesdays has the value 3 (not sure, you have to check that),
then you would add 7 - 3 = 4 days to get to sunday.
 
Try this:

Private Function GetLastDayOfWeek(ByVal dt As Date) As Date
Dim firstDayOfWeek As Integer =
CInt(DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek)
Dim lastDayOfweek As Integer = (firstDayOfWeek + 6) Mod 7

If lastDayOfweek < dt.DayOfWeek Then
Return dt.AddDays(lastDayOfweek - dt.DayOfWeek + 7.0)
Else
Return dt.AddDays(lastDayOfweek - dt.DayOfWeek)
End If
End Function

/claes
 
Back
Top