miket5
(Michael Tunstall)
March 28, 2018, 4:43pm
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
Can anyone help me please
arivu96
(Arivazhagan A)
March 28, 2018, 4:47pm
2
Hi @miket5 ,
What exception are you getting??
Send screenshot
Make sure you are assigning value datatype is System.Datetime
Regards,
Arivu
miket5
(Michael Tunstall)
March 28, 2018, 4:50pm
3
Yes, assigning to System.DateTime.
Exception is: String was not recognized as a valid DateTime.
miket5
(Michael Tunstall)
March 28, 2018, 4:52pm
4
Just have the message on the console as inside a Try Catch block
arivu96
(Arivazhagan A)
March 28, 2018, 4:53pm
5
Use trim function
runStartTimeString.Trim()
miket5
(Michael Tunstall)
March 28, 2018, 5:05pm
6
Tried that, get same exception: String was not recognized as a valid DateTime.
arivu96
(Arivazhagan A)
March 28, 2018, 5:13pm
7
Hi @miket5 ,
Last try make sure in-between date and time is having only one space??
Regards,
Arivu
miket5
(Michael Tunstall)
March 28, 2018, 5:22pm
8
This is one of the dates, I am trying to process 28/03/2018 15:49:56
only one space.
MAHESH1
(MAHESHKUMAR JV)
March 28, 2018, 5:24pm
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
4 Likes
arivu96
(Arivazhagan A)
March 28, 2018, 5:33pm
10
You format is wrong
Use this one
dd/MM/yyyy HH:mm:ss
Custom date format
Regards,
Arivu
3 Likes
miket5
(Michael Tunstall)
March 28, 2018, 5:37pm
11
Thanks very much, that solved the problem.
best regards
Mike