c# - DateTime TryParse problem -
string date = txtworkingdate.text; datetime datetime = datetime.minvalue; if (datetime.tryparse(date, out datetime)) { args.isvalid = true; } else args.isvalid = false;
txtworkingdate.text "dd.mm.yyyy" becouse of validateion false if date not "dd.mm.yyyy". how c check types of date "dd.mm.yyyy", "mm/dd/yyyy" becouse valid.
by using this overload , providing accepted formats:
string date = txtworkingdate.text; datetime datetime; string[] formats = new[] { "dd.mm.yyyy", "mm/dd/yyyy" }; if (datetime.tryparseexact(date, formats, cultureinfo.invariantculture, datetimestyles.none, out datetime)) { args.isvalid = true; } else { args.isvalid = false; }
Comments
Post a Comment