I am fairly new to C#.
I have to build a script that reads a string and tries to convert it to a Date.
The problem are:
-The dates come in different formats. (International, American, Japanese)
-The dates come with different separators, or none at all.
-The year might be complete or just 2 positions
I have begun by replacing the possible separators:
dateinstring = dateinstring.Replace("-","");
dateinstring = dateinstring.Replace(".","");
dateinstring = dateinstring.Replace("/","");
Then check the lenght to see if the year is complete (31102012 or 311012 for example)
if(dateinstring.lenght = 8){
//check format with complete date
}else{
//check format with reduced year
}
Now I stumbled upen this function: DateTime.TryParseExact
which seems to do the same, but it returns a boolean (true or false) and not the date itself.
Am I missing something? Are there methods in C# that already do this or should I go on with my solution?