vb.net Monthcalendar dates

hi,

Is there a way to get the start and end date of the current week?

For example, today is the 7/31/2015, I'd like to get the start date of sunday (July 26), and then the end date of saturday (August 1st) from the calendar.

Basically the week that includes todays date.
FCapoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi FCapo;

This should give you what you need.

Dim dateNow As DateTime = DateTime.Now
'' Get the current day of the week 0 - 6, 0 = Sunday and 6 = Saturday
Dim currentDay As Integer = dateNow.DayOfWeek
'' Get start of the week by subtracting current day of the week
Dim startOfWeek As DateTime = DateTime.Now.AddDays(-currentDay)
'' Get end of the week by adding 6 to start
Dim endOfWeek As DateTime = startOfWeek.AddDays(6)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
it_saigeDeveloperCommented:
*No Points*

Proof of concept using Fernando's recommendation:
Module Module1
	Sub Main()
		Dim now = DateTime.Now
		' Get the current day of the week 0 - 6, 0 = Sunday and 6 = Saturday
		Dim current = now.DayOfWeek
		' Get the start of the week by subtracting current day of week
		Dim start = New DateTime(now.Year, now.Month, now.Day).AddDays(-current)
		' Get the end of the week by adding 6 to the start.
		Dim [end] = start.AddDays(6)

		Console.WriteLine("The first date of the week for {0} is {1}", now.ToShortDateString(), start.ToShortDateString())
		Console.WriteLine("The last date of the week for {0} is {1}", now.ToShortDateString(), [end].ToShortDateString())
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG-saige-
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.