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
And This Output is what i want where Time
is not included
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")}));`
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With