Reputation: 65
Hi I am creating a GridView
data to show my CSV in the web application. I have a gridview
from a data table with the Goods Reciept
Date as DateTime
. Question here is how to remove time from my Date of Goods Reciept
.
public void Storage00B()
{
DataTable StorType00B = new DataTable();
StorType00B.Columns.AddRange(new DataColumn[6] {
new DataColumn("Material", typeof(string)),
new DataColumn("Quantity", typeof(float)),
new DataColumn("Date of Goods Reciept", typeof(DateTime)),
new DataColumn("Date of Last transaction",typeof(string)),
new DataColumn("Stock Status", typeof(string)),
new DataColumn("Storage Type", typeof(string))
});
DataTable dt = GetDataTable();
int B = 0;
int QB = 0;
foreach (DataRow row in dt.Rows)
{
if (row.Field<String>(5) == "00B\r")
{
B++;
if (row.Field<String>(4) == "Q")
{
QB++;
}
}
}
String StrTyp;
for (int i = 0; i < dt.Rows.Count; i++)
{
StrTyp = dt.Rows[i][5].ToString();
StorType00B.Rows.Add();
if (StrTyp == "00B\r")
{
StorType00B.Rows[i][0] = dt.Rows[i][0];
StorType00B.Rows[i][1] = dt.Rows[i][1];
StorType00B.Rows[i][2] = dt.Rows[i][2];
StorType00B.Rows[i][3] = dt.Rows[i][3];
StorType00B.Rows[i][4] = dt.Rows[i][4];
StorType00B.Rows[i][5] = dt.Rows[i][5];
}
}
Stor_Type00B.Text = "Before IQA Stock Quantity :" + B;
Q00B.Text = "Total Quality Stock :" + QB;
StorType00B = StorType00B.Rows.Cast<DataRow>().Where(row => !row.ItemArray.All(field => field is DBNull || string.IsNullOrWhiteSpace(field as string))).CopyToDataTable();
DataView dv = StorType00B.DefaultView;
dv.Sort = "Date of Goods Reciept ASC";
StorageType00B.DataSource = dv;
StorageType00B.DataBind();
}
Here is my current result
As you can see I want to remove the 12:00:00 AM because there's no time in my Goods Reciept
date.
Upvotes: 0
Views: 1343
Reputation: 1996
You should try formatting your date into a string like dd-MM-yyyy
format:
StorType00B.Rows[i][2] = Convert.ToDateTime(dt.Rows[i][2]).ToString("dd-MM-yyyy");
Upvotes: 1
Reputation: 39946
What about converting it to .NET DateTime
and then use the Date
property. Something like this:
StorType00B.Rows[i][2] = Convert.ToDateTime(dt.Rows[i][2]).Date;
Upvotes: 1