Time Format from a DataReader

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
 
G

George

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
 
P

pvong

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")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top