20

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

3 Answers 3

40

Use nullable datetime

    Dim DOB As Nullable(Of Date) = Date.Now
    Dim datestring As String = DOB.Value.ToString("d")
    DOB = Nothing
Sign up to request clarification or add additional context in comments.

1 Comment

it should be DOB.Value.ToStrin("d"), updated answer, check now please
3

“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

6 Comments

You have already given an answer. Don't try to correct other answers by editing them. Why do you want to have two answers that are exactly the same? Please use the comment system to point out mistakes. Thank you.
network problem. Same answer got posted twice, someone removed the second, thanks whoever it is
That's not what I meant. You seem to have tried to edit alliswell's answer so it looks just like yours.
I thought the question was on Date and not DateTime?
@ AltF4_ harness the power thereof, not the syntax
|
-2

Change the DOB from a date variable to an object variable. You can then pass nothing or a valid date into the variable. That variable can then be used update the database.

dim DOB as object = nothing
If chkSdob.Checked = True Then
  DOB = datestring
end if

1 Comment

Why bother? when you have no idea what the question is

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.