首页 > 解决方案 > 将月份添加到给定日期

问题描述

我想将用户给定的月数(例如 2)添加到给定的日期,但我遇到了同样的困难。我试过了

Public Function MyFunction(m_GMonths As Double, m_Given_Date as Date) As Double
    Return  m_Given_Date + m_GMonths
End Function

我得到的错误是Operator '+' is not defined for types 'Date' and 'Double'

有人可以告诉我我做错了什么吗?

标签: visual-studio

解决方案


你应该使用AddMonths

Dim z = DateTime.Now
Dim x = z.AddMonths(2)

推荐阅读