Datetime, SQL Server, Web App, Web Service

I

Iwan Petrow

Hi,

I have a column of type datetime in a SQL Server database. I set and
get this column with Web Services using dataset and send them to a Web
App TextBox control. The collation of the database is
SQL_Latin1_General_CP1_CI_AS (if it necessary I could change it).
I didn't change options in Web service and Web app (web_config).
The date is shown in this format: "mm/dd/yyyy hh:mm:ss AM/PM". I would
like the format to be "dd/mm/yyyy hh:mm:ss" (hh 00-23).

What could I do to fix this problem?

Thanks.
 
C

CSharper

Use DateTime.Parse to get it into a DateTime instance, then set the
TextBox's Text property using the DateTime's ToString method, along with the
format you want.

DateTime myDateTime =
DateTime.Parse(ds.Tables[0].Rows[0]["columnName"].ToString());
myTextBox.Text = myDateTime.ToString("dd/mm/yyyy hh:mm:ss");

You get the idea?
HTH,
Dan Cox
 
H

Hans Kesting

CSharper said:
Use DateTime.Parse to get it into a DateTime instance, then set the
TextBox's Text property using the DateTime's ToString method, along
with the format you want.

DateTime myDateTime =
DateTime.Parse(ds.Tables[0].Rows[0]["columnName"].ToString());
myTextBox.Text = myDateTime.ToString("dd/mm/yyyy hh:mm:ss");

I think it should be "dd/MM/yyyy HH:mm:ss": MM (capitals) is month number,
"mm" (lowercase) is minutes. "HH" is hours in 24-format.
 
C

CSharper

I think he can figure out his own format string, that's probably the least
of his worries.

Hans Kesting said:
CSharper said:
Use DateTime.Parse to get it into a DateTime instance, then set the
TextBox's Text property using the DateTime's ToString method, along
with the format you want.

DateTime myDateTime =
DateTime.Parse(ds.Tables[0].Rows[0]["columnName"].ToString());
myTextBox.Text = myDateTime.ToString("dd/mm/yyyy hh:mm:ss");

I think it should be "dd/MM/yyyy HH:mm:ss": MM (capitals) is month number,
"mm" (lowercase) is minutes. "HH" is hours in 24-format.
You get the idea?
HTH,
Dan Cox
 

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