class Program { static void Main(string[] args) { string date = "19890428"; DateTime dateTime; string[] format = { "MMddyyyy", "ddMMyyyy", "yyyyMMdd", "yyyyddMM" }; if (DateTime.TryParseExact(date, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) { Console.WriteLine( "yes" ); } Console.ReadLine(); } } I get output "yes" -- by looking at the format i can know that it is yyyyMMdd so it is passed in if condition. Is there a way to know at runtime that which format is passed. We are consuming a webservice and the format that we are getting are not sure.It always comes as string. I don't want to do if else to check which format got passed and convert accordingly as below. var x = DateTime.ParseExact(cd13, "yyyyddMM", CultureInfo.InvariantCulture); Kindly suggest.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)