By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,369 Members | 1,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,369 IT Pros & Developers. It's quick & easy.

How to find a last day of the following week?

P: n/a
Hello,

How to find a last day of the next week (or in next two weeks) using VB.NET?
for example:

01-Feb-2005 = 13-Feb-2005
or
09-May-2005 = 22-May-2005
Any help is greatly appreciated,
Adam
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Adam" <ad**@blah.com> wrote in message
news:y2********************@news20.bellglobal.com. ..
How to find a last day of the next week (or in next two weeks) using
VB.NET?
for example:

01-Feb-2005 = 13-Feb-2005
or
09-May-2005 = 22-May-2005

Any help is greatly appreciated,


I'm sure there are very many ways of doing this - here is one suggestion:

Function EndOfNextWeek (pdtmStart As DateTime) As DateTime

Dim intLastDayOfWeek as Integer = DayOfWeek.Sunday ' modify as required

Do until pdtmStart.DayOfWeek = DayOfWeek.Sunday

pdtmStart = pdtmStart.AddDays(1)

Loop

Return pdtmStart.AddDays(7)

End Function
Nov 19 '05 #2

P: n/a
I know you mentioned VB, but here's a C# example.

Basiclly you just need to get the Day of the Week and substract where you're
at in the Day of the Week and pass that to AddDays() (AddDays() accepts
negative numbers) and that'll get you to your start of the week (Sunday).

class Class1
{
static DateTime AheadWeek(DateTime dt, int numOfWeeks)
{
return(dt.AddDays( ( -(Convert.ToInt32(dt.DayOfWeek)) ) + (numOfWeeks *
7) ));
}
[STAThread]
static void Main(string[] args)
{
// Start of this week
DateTime dt = AheadWeek(DateTime.Now, 0);

// One week ahead of todays date
DateTime dt = AheadWeek(DateTime.Now, 1);

// Two weeks ahead of todays date
DateTime dt = AheadWeek(DateTime.Now, 2);

}
}
"Adam" <ad**@blah.com> wrote in message
news:y2********************@news20.bellglobal.com. ..
Hello,

How to find a last day of the next week (or in next two weeks) using
VB.NET?
for example:

01-Feb-2005 = 13-Feb-2005
or
09-May-2005 = 22-May-2005
Any help is greatly appreciated,
Adam

Nov 19 '05 #3

P: n/a
On Mon, 9 May 2005 15:33:29 +0100, "Mark Rae"
<ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote:
"Adam" <ad**@blah.com> wrote in message
news:y2********************@news20.bellglobal.com ...
How to find a last day of the next week (or in next two weeks) using
VB.NET?
for example:

01-Feb-2005 = 13-Feb-2005
or
09-May-2005 = 22-May-2005


Date.Now.AddDays(-Date.Now.DayOfWeek).AddDays(14)

Hope this helps

Tom
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.