How to subtract a month from Date object?

前端 未结 4 1928
名媛妹妹
名媛妹妹 2021-02-06 23:48

How do I subtract a month from a date object in VB.NET?

I have tried:

Today.AddMonths(-1)

However, given that Today is 01-Jan-2010, the

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 00:32

    You actually have to transport Today into a variable and let that assignment work there. The following code will produce the result you expect (I just verified it because your post made me think twice).

    Dim dt As DateTime = Date.Today
    dt = dt.AddMonths(-2)
    
    Dim x As String = dt.ToString()
    

提交回复
热议问题