To add to what Graeme has said, a better solution is to use
DateTime.TryParseExact Method (System) | Microsoft Learn[
^] instead - that way you can spot errors instead of your app crashing if the data isn't in the format you expect for some reason:
DateTime dt;
if (!DateTime.TryParseExact(str, "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
{
... report or log the problem
return;
}
... dt contains a valid date set at midnight here