CSharp examples for System:DateTime Convert
Convert To Date
using System.Globalization; using System.Web; using System.Linq; using System.Collections.Generic; using System;//from ww w. j a v a 2s . co m public class Main{ public static DateTime? ConvertToDate(string inputDateTime, string format = null) { DateTime outputDateTime; DateTime? result = null; var parseFormat = format == null ? "dd-MM-yyyy" : format; var allFormats = Datetime_Formats(parseFormat); foreach (var x in allFormats) { if (DateTime.TryParseExact(inputDateTime, x, CultureInfo.InvariantCulture, DateTimeStyles.None, out outputDateTime)) { result = outputDateTime; } if (result != null) { break; } } return result; } }