Skip to content

Instantly share code, notes, and snippets.

@johnoke
Created October 21, 2022 18:53
Show Gist options
  • Save johnoke/43b3fb9e20e876e3b2609ff378bccc92 to your computer and use it in GitHub Desktop.
Save johnoke/43b3fb9e20e876e3b2609ff378bccc92 to your computer and use it in GitHub Desktop.
public static DateTime FormatDate(string date)
{
DateTime startDate;
string[] formats = { "dd/MM/yyyy", "dd/M/yyyy", "d/M/yyyy", "d/MM/yyyy",
"dd/MM/yy", "dd/M/yy", "d/M/yy", "d/MM/yy", "MM/dd/yyyy", "M/dd/yyyy", "M/d/yyyy", "MM/d/yyyy",
"MM/dd/yy", "yyyy/M/dd", "yyyy/MM/dd", "yyyy-MM-dd", "dd-MM-yyyy", "dd-MMMM-yyyy", "dd-M-yyyy", "d-M-yyyy", "d-MM-yyyy", "dd-MMM-yyyy", "dd-MMM-y", "dd-MMMM-y"};
if (!DateTime.TryParseExact(date, formats, null, DateTimeStyles.None, out startDate))
{
return startDate;
}
else
{
return startDate;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment