|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Week EndingHi 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 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 > 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 > 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 > 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 > >
How do I handle this
RegEx Either Or Newbie question - VB.net, referencing controls Question: arraylist and item Discrepancy in DataGridView column order & databound DataTable Icon.FromHandle(..) not working? last API question.... how to hardcode lots of text into a textbox/RichTextbox? Lauch VB.NET App From Network Drive Or Network Share. Need help/advice to make a decision |
|||||||||||||||||||||||