Advanced Date Validation Using C# (TryParseExact and DateTimeStyles)
Max O'Didily
Advanced Date Validation Using C# (TryParseExact and DateTimeStyles)
Note: Use dd/MM/yyyy instead of dd/mm/yyyy if you wish to use the UK date format. This video had a typo!
Greetings, today we shall be covering a more advanced way to validate a date using C#. This method uses the DateTime class and we attempt to create a DateTime object using our date input as a string. If it works, the date is valid, if it doesn't work the date is invalid.
We can use TryParseExact to speciafy the date format, the culture info and the DateTimeStyles. This gives us more control over what we deem as a valid date.
A follow up tutorial will be uploaded as there is still a lot more to cover.
C# DateTimeStyles documentation: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.datetimestyles?view=net-6.0
C# CultureInfo documentation: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=net-6.0
Subscribe to keep notified when I upload?: https://tinyurl.com/SubMaxODidily
Advanced Date Validation Using C# (TryParseExact and DateTimeStyles) ... https://www.youtube.com/watch?v=yPUoT2G80lI
16657688 Bytes