Link to home
Start Free TrialLog in
Avatar of Ed
EdFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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.
Avatar of Lokesh B R
Lokesh B R
Flag of India image

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

Avatar of Ed

ASKER

Thanks, that works....... however in some cases the record maybe blank and this throws an error.  How can I cater for null values?
ASKER CERTIFIED SOLUTION
Avatar of Lokesh B R
Lokesh B R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ed

ASKER

oh yes, why didn't I think of that.... perfect thanks.