我正试图找出可以为空的日期之间的区别。 DateDiff(DateInterval.Day, firstDate, secondDate)
适用于Date
,但适用于Nullable(Of Date)
。我的日期都是可以为空的字段。
这是错误消息:
重载解析失败,因为没有缩小转换就无法调用可访问的
DateDiff
:
Public Function DateDiff(Interval As String, Date1 As Object, Date2 As Object, [DayOfWeek As Microsoft.VisualBasic.FirstDayOfWeek = FirstDayOfWeek.Sunday], [WeekOfYear As Microsoft.VisualBasic.FirstWeekOfYear = FirstWeekOfYear.Jan1]) As Long
:参数匹配参数Interval
从Microsoft.VisualBasic.DateInterval
缩小为String
。
Public Function DateDiff(Interval As Microsoft.VisualBasic.DateInterval, Date1 As Date, Date2 As Date, [DayOfWeek As Microsoft.VisualBasic.FirstDayOfWeek = FirstDayOfWeek.Sunday], [WeekOfYear As Microsoft.VisualBasic.FirstWeekOfYear = FirstWeekOfYear.Jan1]) As Long
:参数匹配参数Date1
从Date?
缩小为Date
。
Public Function DateDiff(Interval As Microsoft.VisualBasic.DateInterval, Date1 As Date, Date2 As Date, [DayOfWeek As Microsoft.VisualBasic.FirstDayOfWeek = FirstDayOfWeek.Sunday], [WeekOfYear As Microsoft.VisualBasic.FirstWeekOfYear = FirstWeekOfYear.Jan1]) As Long
:参数匹配参数Date2
从Date?
缩小为Date
。
答案 0 :(得分:2)
您必须在可空的.Value
对象上调用Date
。
DateDiff(DateInterval.Day, firstDate.Value, secondDate.Value)
答案 1 :(得分:1)
如果您知道他们不是Nothing
,请获取他们的值:
DateDiff(DateInterval.Day, firstDate.Value, secondDate.Value)
但是你可以利用operator overloading,因为这不是VB6:
(secondDate.Value - firstDate.Value).Days
答案 2 :(得分:-1)
2年后回答问题......:)
上述错误可能是由数据类型未命中匹配引起的。 使用DateValue函数,例如
DateDiff(DateInterval.Day, DateValue(stringwiDate.text), DateValue(string2witDate.text))