How to set Date variable to null in VB.NET
98,599
Solution 1
Use nullable datetime
Dim DOB As Nullable(Of Date) = Date.Now
Dim datestring As String = DOB.Value.ToString("d")
DOB = Nothing
Solution 2
“DateTime is a value type (a structure) and can not be set to null or nothing as with all .Net value types. The default value for a datetime value is zeros for the date portion and 12:00:00 AM for the Time portion.”
VB.NET - Nullable DateTime and Ternary Operator
Author by
gaurav somani
Updated on July 09, 2022Comments
-
gaurav somani almost 2 years
I want to assign the
DOB
variable as null.Dim DOB As Date = DTPSdob.Value Dim datestring As String = DOB.ToString("d") If chkSdob.Checked = False Then DOB = 'I want to assign here DOB variable as null' Else DOB = datestring End If