i have a question.
i need to validate , that date and time in a application is in correct format .
i have this code for this
Code: Select all
dateFormatString = "dd-MM-yyyy HH:mm";
try
{
System.DateTime dt = System.DateTime.ParseExact(dateString, dateFormatString, System.Globalization.CultureInfo.InvariantCulture);
Report.Log(ReportLevel.Info, "Validated date is correct " + dateString + "\r\nValidated date format: " + dateFormatString);
}
catch
{
Report.Log(ReportLevel.Warn, "Validated date in incorrect format. \r\nValidated date: " + dateString + "\r\nValidated date format: " + dateFormatString);
}
i one it passes validation, in second - it gives me an error... And i don't understand why..
Same string validated to same value gives me different results...
Maybe you can help me to understand why? i even check a number of "spaces"..
what can be an issue?
this comes correct
Validated date is correct 17-05-2019 10:19
Validated date format: dd-MM-yyyy HH:mm
this comes with error
Validated date in incorrect format.
Validated date: 17-05-2019 10:19
Validated date format: dd-MM-yyyy HH:mm