I'm trying to export to excel I have string of Date which can be in any format of date but I wanted to convert it to dd-MMM-yyyy format. I have tried every Convert.ToDatetime option which converts only to the System format. I want it to convert dd-MMM-yyyy format.
Thanks Inadvance.
List<UnavailableModel> collection = UnavailableBL.GetAllUnavailableDetails(FilteredFacetsJsonString).Result.ToList();
base.Warning(string.Format("Get {0} number of records ", collection.Count));
List<object> obj = new List<object>();
obj.Insert(0, new string[7] { "NAME", "REGION NAME", "MANAGER NAME", "FROM DATE", "TO DATE", "CATEGORY", "COMMENTS" });
int count = 1;
foreach (var audit in collection)
{
DateTime? dt1 = null, dt2 = null;
string StartDate = null, EndDate = null;
if (audit.FromDate != null)
{
dt1 = Convert.ToDateTime(audit.FromDate);
StartDate = dt1.ToString().Substring(0, 10);
}
if (audit.ToDate != null)
{
dt2 = Convert.ToDateTime(audit.ToDate);
EndDate = dt2.ToString().Substring(0, 10);
}
obj.Insert(count, new string[7]{
string.Format("\"{0}\"", audit.Region_Name),
string.Format("\"{0}\"", audit.First_Name+"
"+audit.Last_Name),
string.Format("\"{0}\"", audit.Manager_First_Name+" "+audit.Manager_Last_Name),
string.Format("\"{0}\"", StartDate),
string.Format("\"{0}\"", EndDate),
string.Format("\"{0}\"", audit.Category),
string.Format("\"{0}\"", audit.Comments)
});
count++;
}
base.Warning(string.Format("Data table created "));
for (int i = 0; i < obj.Count; i++)
{
string[] stringCSV = (string[])obj[i];
for (int j = 0; j < stringCSV.Length; j++)
{
//Append data with separator.
sb.Append(stringCSV[j] + ',');
}
//Append new line character.
sb.Append("\r\n");
}