DateAdd Function in VB.NET / AddDays Function in VB.NET
Sub DateAdd_Example()
Dim CurrentDate As Date
CurrentDate = DateTime.Now
MsgBox("Tomorrow is " & CurrentDate.AddDays(1) & " using AddDays")
MsgBox("Tomorrow is " & DateAdd(DateInterval.Day, 1, CurrentDate) & " using DateAdd")
End Sub
Subtracting Days/Months/Years using VB.NET
Days/Months can be subtracted from the given date by passing a negative value to the DateAdd or AddDays function
Sub DateSub_Example()
Dim CurrentDate As Date
CurrentDate = DateTime.Now
MsgBox("Yesterday was " & CurrentDate.AddDays(-1) & " using AddDays")
MsgBox("Yesterday was " & DateAdd(DateInterval.Day, -1, CurrentDate) & " using DateAdd")
End Sub
No comments:
Post a Comment