C# learner
Active member
- Joined
- Dec 22, 2022
- Messages
- 40
- Programming Experience
- Beginner
The GEDCOM file that I'm working on downloads dates in many different formats, MM/DD/YYYY, YYYY, MM/YYYY, DD Jun YYYY, etc. I created a routine I thought could handle this but the return goes back without changing. Is there a simpler way of doing this or where is the problem?
C#:
static string newDate (string fDate)
{
string inputFormatMMDDYYYY = "MM/dd/yyyy";
string inputFormatDDMONYYYY = "dd MMM yyyy";
string inputFormatMMYYYY = "MM/yyyy";
string outputFormat = "yyyy/dd/MM";
if (fDate.Length == 4)
{
return fDate;
}
else if (fDate.Length == 10)
{
DateTime date = DateTime.ParseExact(fDate, inputFormatMMDDYYYY, CultureInfo.InvariantCulture);
return fDate = date.ToString(outputFormat);
}
else if (fDate.Length == 11)
{
DateTime date = DateTime.ParseExact(fDate, inputFormatDDMONYYYY, CultureInfo.InvariantCulture);
return fDate = date.ToString(outputFormat);
}
else if (fDate.Length == 7)
{
DateTime date = DateTime.ParseExact(fDate, inputFormatMMYYYY, CultureInfo.InvariantCulture);
return fDate = date.ToString(outputFormat);
}
else
{
return fDate;
}
}
Last edited by a moderator: