Datetime problem


#1

Hi,

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:
Knipsel

The result is this:
Knipsel2

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?


#2

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”.


#3

Hi, @ArneDeProft

Refer the below link…
https://stackoverflow.com/questions/28168502/converting-string-dd-mm-yyyy-to-datetime-yyyy-mm-dd-in-c-sharp

I hope this will helpful to You…
Regards,