Problem with DateTime.ParseExact

excel
studio

#1

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


#2

Hi @miket5 ,

What exception are you getting??
Send screenshot

Make sure you are assigning value datatype is System.Datetime

Regards,
Arivu


#3

Yes, assigning to System.DateTime.

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


#4

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


#5

Use trim function
runStartTimeString.Trim()


#6

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


#7

Hi @miket5,

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

Regards,
Arivu


#8

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


#9

@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


#10

You format is wrong

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

Custom date format
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

Regards,
Arivu


#11

Thanks very much, that solved the problem.

best regards

Mike