date format

  • Thread starter Thread starter Claudia Fong
  • Start date Start date
C

Claudia Fong

Hi,

I use the following code to get the date from my db. The format is
5/21/2005, but using the code below it will display: 5/21/2005
12:00:00 AM

label3.Text = Convert.ToString(objReader["ADD_DATE"]);

Is there a way so I can get only the date 5/21/2005 instead of the whole
DATE/TIME??

Can someone help me with this?


Cheers!

Claudi
 
Hi Claudia,

You can use the GetDateTime method of the DataReader and then call the
ToString method of the DateTime object with a formatting arguement:

// assume the date column is the first at the index of zero
label3.Text = objReader.GetDateTime(0).ToString("d");

Cheers,
Steve Goodyear
 
Back
Top