Problem with DateTime.ParseExact

I had some code in an assign statement, that was extracting a date time from an Excel spreadsheet in string format and converting it to a DateTime and assigning it to a DateTime variable. This was working fine in 2018.1.2 but for some reason, throws an invalid date format exception in 2018.1.3

DateTime.ParseExact(runStartTimeString,“dd/MM/yyyy hh:mm:ss”,CultureInfo.InvariantCulture)

where runStartTimeString is like “28/03/2018 07:35:06”

When browsing DateTime in the variable type selector as below, it appears there has been a recent change to the DateTimeFormatProvider

image

Can anyone help me please

Hi @miket5 ,

What exception are you getting??
Send screenshot

Make sure you are assigning value datatype is System.Datetime

Regards,
Arivu

Yes, assigning to System.DateTime.

Exception is: String was not recognized as a valid DateTime.

Just have the message on the console as inside a Try Catch block

Use trim function
runStartTimeString.Trim()

Tried that, get same exception: String was not recognized as a valid DateTime.

Hi @miket5,

Last try make sure in-between date and time is having only one space??

Regards,
Arivu

This is one of the dates, I am trying to process 28/03/2018 15:49:56
only one space.

@miket5
dd/MM/yyyy HH:mm:ss mention this format it will work

Since it is a 24 hour format you have to use HH

Regards
Mahesh

4 Likes

You format is wrong

Use this one
dd/MM/yyyy HH:mm:ss

Custom date format

Regards,
Arivu

3 Likes

Thanks very much, that solved the problem.

best regards

Mike