locked
How do I simplify this? RRS feed

  • Question

  • User-797343556 posted

    Hello people I got a question here. Is it possible for me to simplify this? Basically I want to get the date to be monday. It has to be the monday that is coming. Cool

     

            Dim dow As Integer
            dow = Today.DayOfWeek
            If dow = 0 Then
                dow = 1
            ElseIf dow = 1 Then
                dow = 7
            ElseIf dow = 2 Then
                dow = 6
            ElseIf dow = 3 Then
                dow = 5
            ElseIf dow = 4 Then
                dow = 4
            ElseIf dow = 5 Then
                dow = 3
            ElseIf dow = 6 Then
                dow = 2
            End If

    Tuesday, July 20, 2010 9:24 AM

Answers

  • User-837620913 posted

    Try this:

    Sub Main()
       
    Dim d As Date = Now
       
    Dim nextFriday As Date = DateAdd(DateInterval.Weekday, DayOfWeek.Friday - d.DayOfWeek(), Now)
       
    Console.WriteLine("next friday is " & nextFriday)
       
    Console.ReadLine()
    End Sub
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 20, 2010 9:36 AM