How to find a last day of the following week?

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

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
 
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
 
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);

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

Hope this helps

Tom
 

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

Back
Top