add days to date, subtract two dates in net vb net c# datetime
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim d As New Date(2016, 8, 1)
MsgBox("The date is " & Format("long date", d))
d = DateAdd(DateInterval.Day, 5, d)
MsgBox("The date is " & Format("long date", d))
Dim d1 As New Date(2016, 8, 20)
Dim i As Integer
i = DateDiff(DateInterval.Day, d, d1)
MsgBox(i)
End
End Sub
End Class
Hi, today I will show you how to work with dates,
I will show how to add/subtract days,months,years,minutes,hours,seconds to a date
I will also show how to subtract two dates.
1) add days or any thing to a date.
first I will create a Date Object
now lets add 5 days to it.
to add days or anything we have to use dateadd method
this will add 5 days
if you want to subtract 5 days from it, just use
d = DateAdd(DateInterval.Day, -5, d)
this method can be used to add/subtract days,months,years or any other date/time quantity
ex:to add year
lets check, I have added 5 years to it
2) how to subtract two dates
to subtract 2 dates, you have to use datediff method
you can use any date/time quantity
thanks for watching
kindly subscribe our channel to get more videos.