Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude time from date column

Hello Guys :) I have this little problem regarding C# syntax. this is my code

 listView1.Items.Add(new ListViewItem(new string[] {dr["Date"].ToString() }));

This is the Output

enter image description here

And This Output is what i want where Time is not included

enter image description here

I tried this

lisView1.Items.Add(new ListviewItem(new string[] {dr["Date"].ToString("YYYY-MM-DD")}));`
lisView1.Items.Add(new ListviewItem(new string[] {dr["Date"].ToString("yyyy-mm-dd")}));`
like image 600
Karlx Swanovski Avatar asked Jun 23 '13 14:06

Karlx Swanovski


People also ask

How do I separate a date and time in a column?

If a cell contains a combined date and time, you can use the INT function to pull the time value into a separate column. Dates are stored as numbers in Excel, with the decimal portion representing the time.

How do I remove the time from a date in a pivot table?

You may need to highlight the cells, click on "Format Cells..." and change the number format to Date instead. This will convert all the timestamp info inside the cell to show only the dates, not the time. Save this answer.

How do I extract dates in Excel without time?

The following formula will help you converting date/time format cell to date only in Excel. 1. Select a blank cell you will place the date value, then enter formula =MONTH(A2) & "/" & DAY(A2) & "/" & YEAR(A2) into the formula bar and press the Enter key.


1 Answers

Since dr["Date"] returns object which you cannot use overload ToString method of DateTime, so convert to DateTime first by using Field<T> then use correct DateTime format M/d/yyyy in ToString method:

dr.Field<DateTime>("Date").ToString("M/d/yyyy");

You also can refer DateTime format in C# in here.

like image 137
cuongle Avatar answered Sep 22 '22 06:09

cuongle