Home All Groups Group Topic Archive Search About
Author
25 Jul 2006 7:56 PM
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

Author
25 Jul 2006 8:24 PM
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



Show quoteHide quote
"csgraham74" <csgraha***@gmail.com> wrote in message
news:1153857386.986063.315430@b28g2000cwb.googlegroups.com...
> 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
>
Author
25 Jul 2006 8:39 PM
Göran_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.

csgraham74 wrote:
Show quoteHide quote
> 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
>
Author
26 Jul 2006 3:38 PM
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

Show quoteHide quote
"csgraham74" <csgraha***@gmail.com> wrote in message
news:1153857386.986063.315430@b28g2000cwb.googlegroups.com...
> 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
>
Author
31 Jul 2006 11:55 AM
csgraham74
Thanks guys you help had been greatly appreciated

CG


Claes Bergefall wrote:
Show quoteHide quote
> 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
>
> "csgraham74" <csgraha***@gmail.com> wrote in message
> news:1153857386.986063.315430@b28g2000cwb.googlegroups.com...
> > 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
> >