sarepta sarepta - 3 months ago 12
Vb.net Question

subtracting times in vb

I want to subtract 18 years from a VB date object.

Here's the code example:

Dim someVar
DirectCast(pcontrol, DateTimePicker).Value = Date.Now.Subtract(someVar)


someVar value is ?

Answer

It can seem odd, but try using AddYears, but with a negative number:

With DirectCast(pcontrol, DateTimePicker)
  .Value = .Value.AddYears(-18)
End With

or as MarkJ points out, trying to subtract it from now:

With DirectCast(pcontrol, DateTimePicker)
  .Value = Now.AddYears(-18)
End With
Comments