ahn661707
(Ahn661707)
September 16, 2020, 1:33pm
1
I am trying to compare two variables in a For Each Loop. One is a ‘String’, the other is a 'DataTime."
I’ve tried converting the string to the DateTime type using:
datetime.ParseExact(row.Item(“Date”),“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
But keep on getting the error “Options Strict On disallows implicit conversion from ‘Object’ to ‘String’”
What should I do to compare these two variables?
try converting the date time one to string and see if it works
also check this maybe it can help: Learn How To Compare Dates In UiPath - YouTube
ppr
(Peter Preuss)
September 16, 2020, 4:28pm
3
Give a try to and use IT for compare with a datetime
datetime.ParseExact(row.Item(“Date”).toString ,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
bcorrea
(Bruno Correa)
September 16, 2020, 5:17pm
4
Hi, welcome to the community!
if you are getting that error, most likely that datatable column named Date is already of DateTime type… You should not try to parse it as a date again…
ahn661707
(Ahn661707)
September 20, 2020, 4:19am
5
Hi, thanks for your response!
When I try to assign the variable however to just “row.item(0)” I get the error:
"Cannot assign from type ‘System.Object’ to type ‘Sytem.DateTime’ in Assign activity ‘Assign.’
So my new question is. How do you convert an Object to a DateTime?
Thanks
ahn661707
(Ahn661707)
September 20, 2020, 4:20am
6
Hello, thanks for your response. I am trying to compare two dates, so converting it to a string does not compare correctly.
ahn661707
(Ahn661707)
September 20, 2020, 4:21am
7
Hello, thanks for your response. I have tried this, and I would still get the same error sadly.
@ahn661707
Use row.item(0). ToString
and then you can use Compare Date Activitiy. It is explained completely in the video I have shared.
ppr
(Peter Preuss)
September 20, 2020, 12:00pm
9
@ahn661707
have a look below
Line 1: a date value from the row’s Date column
Line 2: the parsing result
Line 3: the parsing in a short form, when System.Globalization is imported as following:
in case of your implementation is not working as expected then go for debugging / setting Breakpoints and analyse the different variable values and statetements. Quick statement checks can be be done in the watch / immediate panel as well
ahn661707
(Ahn661707)
September 21, 2020, 4:56am
10
I was able to fix the problem. Thanks so much! Should’ve watched the video in full first time around.
system
(system)
Closed
September 24, 2020, 5:01am
12
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.