0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【VB.Netの要注意点】DateAddの年(y)指定

Posted at

VB6でも同じだったのですが、例えば 2020/1/1 の1年前の日付計算:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim d1 As Date

    d1 = DateAdd("y", -1, #2020/1/1#)
    MsgBox("2000/1/1 -> " & d1.ToString, vbOKOnly)
    d1 = DateAdd("m", -12, #2020/1/1#)
    MsgBox("2000/1/1 -> " & d1.ToString, vbOKOnly)
End Sub

下は、2019/01/01 ですが
上は、そうではありません。
きっちり1年間とするなら、"m"で 12 とし、
"y"は使うべきでないです。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?