Created
October 21, 2022 18:53
-
-
Save johnoke/43b3fb9e20e876e3b2609ff378bccc92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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