How do you display the week ending date (Sunday) in VB10? When a form loads, I want to display the upcoming Sunday date in a label. In VB6 I used the following code and it worked fine.

Private Sub Form_Load()
' Set Default "Week Ending" Date
lblWkEndDate.Caption = (Date + 7) - (Weekday(Date)) + 1
End Sub

Any and all help would be greatly appreciated. Thank you.

Recommended Answers

All 4 Replies

Dim nextSunday As Integer

nextSunday = (DateTime.Now.AddDays(7)).Day - (Weekday(DateTime.Now)) + 1

Thank you very much.

How would I get the date into format mm/dd/yyyy?

Try

nextSunday.ToString("MM/dd/yyyy")
Dim dt As DateTime = DateTime.MinValue

dt = DateTime.Now.AddDays(7 - Weekday(DateTime.Now) + 1)

Console.WriteLine(dt.ToString("MM/dd/yyyy"))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.