Wednesday, May 03, 2006 7:23 AM
What's the best way of passing in Null / empty date fields as parameters to functions ?
What's the best way of passing in a date into a VB function as a null/empty value - at the moment I am checking to see if it = #12:00:00 AM# , but this seems somewhat haphazard !
Wednesday, May 03, 2006 7:30 AM
Test if date variable is nothing:
Dim testDate As Date = Nothing
testDate = Date.Now
Private Function DateIsNull(ByVal testDate As Date) As Boolean
If testDate.Equals(Nothing) Then
Wednesday, May 03, 2006 2:28 PMModerator
If you are using VB 2005, you can use the Nullable(Of Date) as your parameter. Of course, that would mean you would need to either use a Nullable(Of Date) property/field that you were passing or create a new Nullable(Of Date) that you pass in to the method. Once you have a Nullable(Of Date), you can see if it is empty by checking the .HasValue property. Here's a small snippet:Dim x As New Nullable(Of Date)
x = #1/1/2006#