开发者

how to show only date?

开发者 https://www.devze.com 2022-12-30 18:58 出处:网络
I have a column in the data table called CurrentDate as datatype string (12/2/1983). When I am displaying on the screen this is showing as 12/2/1983 12:00:00AM.

I have a column in the data table called CurrentDate as datatype string (12/2/1983).

When I am displaying on the screen this is showing as 12/2/1983 12:00:00AM.

I am not sure 开发者_如何学Gowhy I am getting timestamp here?

Can anybody help me out?


If you are binding this from a datasource, like a SQL Data Source, you can use CONVERT in your query:

CONVERT(VARCHAR(10),nameOfColumn,101) AS Date

If you need to do this in C#, try the ToShortDateString() method:

string date = myDate.ToShortDateString();


In C# if you convert it to a DateTime object:

DateTime.ToShortDateString();


Are you using data binding to a gridview, formview, or other formatable data source? If so you can simply use the "d" format flag, like below:

<asp:BoundField DataField="MyDate" DataFormatString="{0:d}" HeaderText="My Date" /> 


An example of its usage within the context of setting a label would be:

MyLabel.Text = DateTime.Now.ToString("A FORMATTING STRING HERE);

Two very useful MSFT posts I use are: "Standard DateTime formatting strings" and "Custom date time formatting strings"

0

精彩评论

暂无评论...
验证码 换一张
取 消