Four of these are easily solvable, two are not.
Your first step should be to remove the spaces and replace them with periods. This is necessary because in the case of the French DateTime, the month must have a period to be parsed. As far as .NET is concerned, “avr.” is a valid month and “avr” is not.
So, if your date is in a string called my_datetime_string, then the following code will store it as a DateTime:
my_datetime = DateTime.Parse(my_datetime_string.Replace(" ",".")
This approach will work for:
APR 17 2019
If you try this and it fails then perhaps the date is in French. To parse the date in french (17 AVR 2019) you need to add the culture info parameter:
my_datetime = DateTime.Parse(stringVar,new system.Globalization.CultureInfo("fr-FR"))
To print either of these DateTime objects as “2019-04-07” you can do
As for the other two formats, you may need to do some manual processing. The computer has no way to automatically determine that “190417” and “170419” are the same date, since either could mean April 17, 2019 or April 19, 2017. If you know the position of the data you can use DateTime.ParseExact to tell the computer which data to take as the day/month/year:
DateTime.ParseExact(stringVar,"yyMMdd",new system.Globalization.CultureInfo("en-US")).ToString("yyyy-MM-dd") will parse “190417” as April 17, 2019 and “170419” as April 19. 2017.