Datetime problem



Via a site i’m downloading an Excel. I need to convert the datetime to a specific value

First I tested the value using this:

The result is this:

When I try to convert the datetime to another format I get this error:

While I’m using this function:

"formaat: " + DateTime.ParseExact(newEndDateCognos.ToString, new String(){"MM/dd/yyyy hh:mm:ss","MM/d/yyyy hh:mm:ss","MM/dd/yyyy","MM/d/yyyy","yyyy/MM/dd","yyyy/MM/d","yyyy/MM/d hh:mm:ss","yyyy/MM/dd hh:mm:ss", "yyyy-MM-dd","yyyy-MM-d","yyyy-MM-d hh:mm:ss","yyyy-MM-dd hh:mm:ss","d/MM/yyyy","dd/MM/yyyy","d/MM/yyyy hh:mm:ss","dd/MM/yyyy hh:mm:ss", "d-MM-yyyy","dd-MM-yyyy","d-MM-yyyy hh:mm:ss","dd-MM-yyyy hh:mm:ss"}, CultureInfo.CurrentCulture,DateTimeStyles.None).ToString("d/MM/yyyy")

Yes, I need that many options because the downloaded Excel is very unpredictable.

What am I doing wrong?


First image shows default format “05/15/2018 14:24:00”, so you need a format string “MM/dd/yyyy HH:mm:ss” instead of “MM/dd/yyyy hh:mm:ss”.


Hi, @ArneDeProft

Refer the below link…

I hope this will helpful to You…