I have the following code to check whether or not a datetime value is null or has a value. If it's null, I want it to be returned as a blank string, else it should be a string of the value it contains.
The Else
part of the statement works, it converts the value into a string, however, if the value being passed in as a datetime is null, it doesn't return Nothing
, it instead sets the value to '12:00:00 AM`, which is causing me problems elsewhere in the project.
How can I adapt this function to make null datetime values return as blank strings?
Public Shared Function dbToDate(o As Object) As DateTime
If o Is DBNull.Value Then
Return ""
Else
Return Convert.ToDateTime(o)
End If
End Function