How to find a last day of the following week?

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
 
M

Mark Rae

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
 
G

gabe garza

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

}
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top