DateTime parsing issue

Gerard Young asked on March 25, 2020 14:34

Hi,

I have a field in a web part with a Data type of "Date and time"

The data resolves as

GetValue("Time")| "3/25/2020 12:50:06 PM" | object {string}

When I try to parse the selected date in the web part code using standard "DateTime.parse()" I get the error: String was not recognized as a valid DateTime

When I try to use Kentico ValidationHelper it parses the default value.

ValidationHelper.GetDateTime(GetValue("Time"), DateTime.MinValue) | {01/01/0001 00:00:00} | System.DateTime

Why can't I parse the output of this field as a c# DateTime?

Correct Answer

Gerard Young answered on March 25, 2020 16:24

Turns out it was because of the American date format.

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.