Avatar of FCapo
FCapo
 asked on

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.
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
it_saige

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
it_saige

*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-
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes