Datatime Issue

feras80

New member
Joined
Mar 3, 2008
Messages
2
Programming Experience
Beginner
I have an access file that contain a field "end_date" with datetime datatype
well, i wanna add 1 year to this field.
I tried this:

VB.NET:
 Sub add_data()
        Dim dt As New DataTable
        Me.daPO.Fill(dt)
        Dim i As Integer
        Dim tDate As DateTime

        For i = 1 To dt.Rows.Count - 1
            
                tDate =  dt.Rows(i).Item("date_expires")

                tDate.AddYears(1)

                MsgBox(tDate) ' for testing purpose 
 
        Next

    End Sub

the msgbox returns the same date, means wethout adding 1 year to it. any help here?

Thank you
 
I believe the .AddYears() function returns a new instance of DateTime with the years added to it. Try doing

VB.NET:
tDate = tDate.AddYears(1)
 
Back
Top