[ACCEPTED]-Remove timestamp from date in C#?-date-format
Instance of DateTime class has ToShortDateString 1 method that displays Date only
Maybe:
date.ToString("yyyy-MM-dd");
0
Probably the easiest way to do this is to 5 use the parse function within the DateTime 4 class which takes a string in the format 3 you've described:
http://msdn.microsoft.com/en-us/library/1k1skd40%28v=VS.90%29.aspx
You can then use the 'Date' property 2 within the class to get the date without 1 the time stamp.
Hope this helps.
try
DateTime d ="2011-03-29 00:00:00';
string strDate = d.ToShortDateString();
Or
string strDate = d.ToString("dd/MM/yyyy");
0
There are a few ways to do this, however 10 some depend on assumptions.
a) convert it 9 date/time and then output just the date, the 8 time is still there if you had wanted it b) copy 7 the string upto the first space c) copy 6 the first 11 characters (eg the date) d) regex 5 the output to confirm its a date/time format 4 and then pull out the date
It depends a little 3 I guess on what you want to do with it after 2 and assuming it is a string in the first 1 place. if not myDateTime.tostring('Y-M-D')
would work.
DataColumn date = new DataColumn("date");
date.DataType = System.Type.GetType("System.String");
SomeDataTable.Columns.Add(date);
date.SetOrdinal(n); //placing it in the n+1th position
//n is where the actual column you want to replace is
foreach (DataRow dr in SomeDataTable.Rows)
{
DateTime date;
if (DateTime.TryParse(dr["date"].ToString(), out date))
{
dr["date"] = convert.ToDateTime(dr["date"]).ToString("MM/dd/yyyy");
}
}
SomeDataTable.Columns.RemoveAt(n-1);
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.