Week Ending

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
 
S

Samuel Shulman

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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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.
 
C

Claes Bergefall

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top