converting date .....

  • Thread starter Thread starter Gary Smith
  • Start date Start date
G

Gary Smith

I my SQL Datareader I am loading the date data into text box.

Here is my code

txtActOpenDate.Text = MyDataReader("ActOpenDt").ToString()


txtActOpenDate.Text is displaying the date and time.
How to display the date alone here.
Thanks for your advice.
Gary
 
Cast your value to a date or datetime type and tell it the format to
display.

Ctype(MyDataReader("ActOpenDt"), DateTime).ToShortDateString

If the data value can be null use

String.Format("{0:d}",MyDataReader("ActOpenDt").ToString)

null values get returned as an empty string. The little "d" tells the
system to format as short date value.


Enjoy,
Yogs
www.stellarodyssey.com
 
It would be easier to modify your sql query. Try CONVERT or DATEPART
functions.

Hope this helps,
 
You're almost there:

txtActOpenDate.Text = MyDataReader("ActOpenDt").ToString("mm/dd/yyyy")

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top