There is a SQL Server 2008 database for which I have to create a management software. The database contains a column named DateOfCreation. The table designer made this column as string and gave freedom to users to add date in any format they want and this was really a silly mistake by him. Now some users added as “24 Jan” or
“Jan 24” or “1991 1 12” and many unknown formats. What I want is that when I fetch this string date, a function should be called that will check the format and return -1 if date is not in correct format else return the converted date in DD/MM/YYYY. So how can I check the format of the date that string date variable is containing?
There is a SQL Server 2008 database for which I have to create a
Share
use
DateTime.TryParseExactwith your date format, it will return false in case if the date format is different or invalid.For multiple formats you can specify multiple formats in a string array and then use that in
DateTime.TryParseExactsomething like:From MSDN – DateTime.TryParseExact Method (String, String[], IFormatProvider, DateTimeStyles, DateTime%)