Time Format from a DataReader

  • Thread starter Thread starter pvong
  • Start date Start date
P

pvong

Doing this in VB.NET w VS2008.

In my Sql, I have a SmallDateTime datatype. I have a simple TextBox1. I
have a simple DataReader set up to pull this value. All I want is the time
piece and it's coming over as the whole thing of 1/1/1900 2:45 PM. I only
want 2:45. Can someone help me format this? This is my line.

Textbox1.Text = dr.item("Time")

Thanks!
Phil
 
pvong said:
Doing this in VB.NET w VS2008.

In my Sql, I have a SmallDateTime datatype. I have a simple TextBox1. I
have a simple DataReader set up to pull this value. All I want is the
time piece and it's coming over as the whole thing of 1/1/1900 2:45 PM. I
only want 2:45. Can someone help me format this? This is my line.

Textbox1.Text = dr.item("Time")

Thanks!
Phil


Just format it yourself
Textbox1.Text = ((DateTime)dr.item("Time")).ToString("MM/dd/yy");

George
 
I got it to work, but this is probably not the best way. I had to convert
it to DateTime and then Convert it back to String.

CType(dr.Item("Time"), DateTime).ToString("h:mm")
 
Back
Top