Windows Phone Developers

Thursday, August 14, 2008

Adding and Subtracting Days/Months/Years to a given date using Vb.NET

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

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment