2

VB の日付オブジェクトから 18 年を減算したいと考えています。
コード例は次のとおりです。

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

someVar 値は ?

4

1 に答える 1

8

奇妙に思えるかもしれAddYearsませんが、負の数で を使用してみてください:

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

またはMarkJが指摘するように、今からそれを差し引こうとしています:

With DirectCast(pcontrol, DateTimePicker)
  .Value = Now.AddYears(-18)
End With
于 2012-04-25T16:06:37.840 に答える