I am trying to set up a date range filter on my UI, with checkboxes to say whether a DateTimePicker's value should be used, e.g.
Dim fromDate As DateTime? = If(fromDatePicker.Checked, fromDatePicker.Value, Nothing)
Yet setting fromDate
to Nothing
doesn't result in it being set to Nothing
but to '12:00:00 AM', and the following If
statement incorrectly executes the filter because startDate
is not Nothing
.
If (Not startDate Is Nothing) Then
list = list.Where(Function(i) i.InvDate.Value >= startDate.Value)
End If
How do I really ensure startDate
gets a value of Nothing
?
Nothing
in VB is closer to beingdefault(T)
in C#, rather thannull
. Note that the two are equivalent for reference types. – ImperishableNew Date
as a magic number that means "No Date". – FourchettefromDate
andstartDate
– FourchettestartDate
is a parameter in a method I passfromDate
to. – Kielty