我想从VB日期对象中减去18年.
这是代码示例:
Dim someVar
DirectCast(pcontrol, DateTimePicker).Value = Date.Now.Subtract(someVar)
Run Code Online (Sandbox Code Playgroud)
someVar值是?
这看似奇怪,但尝试使用AddYears,但负数:
With DirectCast(pcontrol, DateTimePicker)
.Value = .Value.AddYears(-18)
End With
Run Code Online (Sandbox Code Playgroud)
或者正如MarkJ指出的那样,试图从现在开始减去它:
With DirectCast(pcontrol, DateTimePicker)
.Value = Now.AddYears(-18)
End With
Run Code Online (Sandbox Code Playgroud)