C# convert string to date

Last modified: June 29, 2021
static void Main(string[] args) { string dateString = "2021-01-05"; DateTime date1; DateTime.TryParseExact(dateString, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out date1); //convert based on date format }