public static DateTime? CleanDateField(string DateField) { double d = double.Parse(DateField); // Get the converted date from the OLE automation date. DateTime conv = DateTime.FromOADate(d); // Convert the text to DateTime and return the value or null DateTime? CleanDate = new DateTime(); int intDate; bool DateIsInt = int.TryParse(DateField, out intDate); if (DateIsInt) { // If this is a serial date, convert it CleanDate = DateTime.FromOADate(intDate); } else if (DateField.Length != 0 && DateField != "1/1/0001 12:00:00 AM" && DateField != "1/1/1753 12:00:00 AM") { // Convert from a General format CleanDate = (Convert.ToDateTime(DateField)); } else { // Date is blank CleanDate = null; } return CleanDate; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)