public static string[] Months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
public static string ReformatDate(string date) {
string[] segments = date.Split();
string year = "", month = "", day = "";
foreach(string seg in segments)
int monInd = Array.IndexOf(Months, seg) + 1;
month = monInd < 10 ? "0" + monInd : monInd.ToString();
else if (char.IsLetter(seg.LastOrDefault()))
string daySeg = seg.Substring(0, seg.Length - 2);
int dayN = Convert.ToInt32(daySeg);
day = dayN < 10 ? "0" + daySeg : daySeg;
return year + "-" + month + "-" + day;
public static void Main()
Console.WriteLine("UniLecs");
Console.WriteLine(ReformatDate("18th Aug 2021"));
Console.WriteLine(ReformatDate("14th Apr 1990"));
Console.WriteLine(ReformatDate("3rd Sep 1994"));