datetime

G

Guest

I am using C#, Windows forms and SQL Server. Part of the data that I am
having problems with is defined as datetime. When I insert the field into
the datebase it is formated as "MM/dd/yyyy", and the data stored in the
database looks like this "06/07/2005". When I open the form and fill the
dataset the date looks like this "06/07/2005 12:00 PM". the question is what
do I do to get rid of the time which is not correct. Help!!!
 
J

John B

nbohana said:
I am using C#, Windows forms and SQL Server. Part of the data that I am
having problems with is defined as datetime. When I insert the field into
the datebase it is formated as "MM/dd/yyyy", and the data stored in the
database looks like this "06/07/2005". When I open the form and fill the
dataset the date looks like this "06/07/2005 12:00 PM". the question is what
do I do to get rid of the time which is not correct. Help!!!

There is no such thing as a Date structure, only datetime.
You would need to format the form to only display the date part
(MM/dd/yyyy) instead of the datetime.

JB

PS. By default the time portion of the datetime should be 0.00.00.00 (12
AM).
I have come across times where the current time was used when not
specified though (IIRC).
 
G

Guest

Hi,
you can convert it to shortdate string like the one below,

dap.Fill(ds);
DateTime dd =Convert.ToDateTime(ds.Tables[0].Rows[0].ItemArray[0].ToString());
textBox1.Text = dd.ToShortDateString();

regards, Daya PSP India
 
J

John B

Daya said:
Hi,
you can convert it to shortdate string like the one below,

dap.Fill(ds);
DateTime dd =Convert.ToDateTime(ds.Tables[0].Rows[0].ItemArray[0].ToString());

If its in the dataset as a boxed datetime, why would you convert it to a
string first?

DateTime d = (DateTime)ds.tables[0].rows[0].itemarray[0];
textBox1.Text = dd.ToShortDateString();

That sounds good though :)

JB
 

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