Reputation: 13
I’m trying to find the difference between nullable dates. DateDiff(DateInterval.Day, firstDate, secondDate)
works for Date
, but not for Nullable(Of Date)
. Both my dates are nullable fields.
This is the error message:
Overload resolution failed because no accessible
DateDiff
can be called without a narrowing conversion:
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
: Argument matching parameterInterval
narrows fromMicrosoft.VisualBasic.DateInterval
toString
.
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
: Argument matching parameterDate1
narrows fromDate?
toDate
.
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
: Argument matching parameterDate2
narrows fromDate?
toDate
.
Upvotes: 1
Views: 2117
Reputation: 1
2 Years Late to Answer the question.... :)
The error Above could be caused by a data type miss match. Use DateValue function e.g
DateDiff(DateInterval.Day, DateValue(stringwiDate.text), DateValue(string2witDate.text))
Upvotes: -1
Reputation: 224942
If you know they’re not Nothing
, get their values:
DateDiff(DateInterval.Day, firstDate.Value, secondDate.Value)
But you can take advantage of operator overloading, since this isn’t VB6:
(secondDate.Value - firstDate.Value).Days
Upvotes: 1
Reputation: 9024
You have to call the .Value
on the nullable Date
object.
DateDiff(DateInterval.Day, firstDate.Value, secondDate.Value)
Upvotes: 2