With these it helps The year 201 being invalid is business logic - if you want to have logical safeguards on your imported data (and you should), do them explicitly. With C# you can easily add an extension method to DateTime if you want, something like
public static DateTime ParseDateWithSanity(this DateTime, string date)
dt = DateTime.Parse(date);
if dt.Year < 1900
I wish this helpful for you The easiest way to validate the format is to actually try converting the string using your date formatter. If it returns nil then the format isn't a match and you can try the other format.
Best Way To Validate a Date String With a Dynamic Date Format
I hope this helps you . There is a dynamic date format where user can specify it somewhere. I need to validate the user input (most likely via js) on a date field when he input it manually (not via datepicker).
may help you . If you are using java 8 then DateTimeFormatter is what you are looking for. The link to javadoc also contains sample code and a number of predefined formats. Besides you can also define your own. Here is some code, an example from the same link:
LocalDate date = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd");
String text = date.format(formatter);
LocalDate parsedDate = LocalDate.parse(text, formatter);
Validate Date FORMAT (not date string) using MomentJS?