sarepta sarepta - 1 year ago 88 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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download