kumar
kumar

Reputation: 2944

how to show only date?

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 why I am getting timestamp here?

Can anybody help me out?

Upvotes: 0

Views: 4178

Answers (4)

Famous Nerd
Famous Nerd

Reputation: 416

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"

Upvotes: 0

cortijon
cortijon

Reputation: 983

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

Upvotes: 1

kemiller2002
kemiller2002

Reputation: 115508

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

DateTime.ToShortDateString();

Upvotes: 1

Matthew Jones
Matthew Jones

Reputation: 26190

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();

Upvotes: 2

Related Questions