473,396 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to find a last day of the following week?

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
3 1662
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: pyuk2005 | last post by:
The UK Python Conference for 2005 will take place at the Randolph Hotel, Oxford on 20-23 April 2005. This is the FINAL CALL for talks. The original deadline of 26th December has been extended...
13
by: SimonC | last post by:
I would like to return data from the last 2 weeks of each given month in Javascript, but in 2 formats. So, the penultimate week (Monday to Sunday) and the last week (Monday to ??) I'm not...
3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
25
by: Tor Erik Sønvisen | last post by:
Hi I need to browse the socket-module source-code. I believe it's contained in the file socketmodule.c, but I can't locate this file... Where should I look? regards tores
1
by: Hadi | last post by:
Hello, I have to DateTime structure, how do I calculate if date A is on the same week with date B or last week of date B? Thanks, Hadi
0
by: Lee Harr | last post by:
I wrote a function to return the first date of a given week (and a few related functions) : -- return the first date in the given week CREATE or REPLACE FUNCTION week_start(integer, integer)...
5
by: amanda27 | last post by:
I have a database that we use in our department for the status of our projects. In the form when you pick a project from the dropdown list I have a subform that pulls the data entered for the...
4
by: Charlotte | last post by:
Hi, is it possible to determine the first and the last day of a week (with classic ASP) nu = "06/01/2008" week = (DatePart("ww",nu)) firstday = dateadd("d",(-datepart("w",date())),nu)...
0
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.