Asp.net(vb) Format textbox as date no time.

How do I format a value from the DB as just dd/mm/yyyy

txtDateCompleted.Text = objDR3("DATECOMPLETED")

shows as -    22/05/2014 00:00:00

I'd like to get rid of the   00:00:00

I have tried

 txtDateCompleted.Text = objDR3("DATECOMPLETED").ToString("dd/MM/yyyy")


but this does not work.
EdAsked:
Who is Participating?
 
Lokesh B RDeveloperCommented:
Hi,

You can check for NULL as below.

If objDR3("DATECOMPLETED") IsNot Nothing Then
	txtDateCompleted.Text = Convert.ToDateTime(objDR3("DATECOMPLETED")).ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)

End If

Open in new window

0
 
Lokesh B RDeveloperCommented:
Hi,

Any of the following will do the job for you.

txtDateCompleted.Text = Convert.ToDateTime(objDR3("DATECOMPLETED")).ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)

Open in new window


OR

txtDateCompleted.Text = Convert.ToDateTime(objDR3("DATECOMPLETED")).ToString("dd/MM/yyyy")

Open in new window

0
 
EdAuthor Commented:
Thanks, that works....... however in some cases the record maybe blank and this throws an error.  How can I cater for null values?
0
 
EdAuthor Commented:
oh yes, why didn't I think of that.... perfect thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.