How to calculate the date six months from the current date in VB.NET

1 Answer

0 votes
Imports System

Class Program
    Private Shared Function AddMonthsToDate(ByVal months As Integer, ByVal Optional dt As DateTime? = Nothing) As DateTime
		Dim targetDate As DateTime = If(dt, DateTime.Now)
        Return targetDate.AddMonths(months)
    End Function

    Public Shared Sub Main()
        Dim futureDate As DateTime = AddMonthsToDate(6)
        Console.WriteLine("Date six months from now: " & futureDate.ToString("yyyy-MM-dd"))
    End Sub
End Class
	

' run:
'
' Date six months from now: 2025-12-12
'

 



answered Jun 12 by avibootz
...