Reputation: 5250
I have this string July 1, 2021 9:10 AM
and I'm trying to parse it into a DateTime
variable.
This isn't working for me. ST
is a variable that has the string representation of the date and time.
var Event = DateTime.ParseExact(ST, "MMMM dd, yyyy h:mm tt", CultureInfo.InvariantCulture);
Upvotes: 0
Views: 628
Reputation: 6103
You are using the wrong day format. For a month day without a leading zero, you should use the following:
var Event = DateTime.ParseExact(ST, "MMMM d, yyyy h:mm tt", CultureInfo.InvariantCulture);
Upvotes: 4