I have a column in Excel, called “StartTime” with MM/dd/yyyy hh:mm:ss format. I want to get that “StartTime” data in Uipath and subtract that with the “CurrentTime” ie date time.now (RunningTime= CurrentTime- StartTime).
I tried getting the “Starttime” in a string using (StrTime = row.item(“StartTime”).toString and the next step to convert it to a Datetime using StartTime= convert.datetime(date time.ParseExact(Strtime,“MM/dd/yyyy hh:mm:ss”,system.Globilization.CultureInfo.InvariantCulture))
Is this the correct logic because I keep getting Error: "Assigned String was not converted to date time.
I tried with StartTime=datetime.ParseExact(Strtime,“MM/dd/yyyy HH:mm:ss”,system.Globilization.CultureInfo.InvariantCulture) and also used Trim() in StrTime and getting the same Error: “String was recognized as valid date time”
Hi Peter, Thank you! I am succesfuly able to proceed to subtraction after following your details.
For subtracting,I used Running time= (CurrentTime.subtract(StartTime)).toString(“hh:mm”) for data(Current time : 07/28/2021 18:00 AND StartTime= 07/26/2021 13:00), and it gives incorrect result as 23:52
The result should be nearly 48 Hrs time.
if your country format/system format is dd/MM/yyyy then datetime.parse will not work. so in that case, just replace it with datetime.parseexact and use total hours, as shown below…
Hi Prasath, Yes I need difference of total Hours as result.
I have 3 Variables( CurrentTime of type: Datetime, StartTime of type: DateTime, and RunningTime of type string). To calculate the RunningTime: (RunningTime= CurrentTime- StartTime), I tried to use your statement and getting error that "Conversion from “double to string " is not allowed”
Got it. Please let me know, how you are getting the current time (like “now”) and starting time? Provide sample values…PLease check below…Here StartDate and End Date are both datetime variables…
That worked Wonderfully! Thank you so much. I am able to get total running hours (Eg: 46Hrs).
If I want to check that Total hours > 6 hours, Can I assign 06:00 hours to a string variable and compare? I just wanted to make sure it won’t take 6 o clock instead of 6 hrs?
it will not work. because your total hours is string…which you have to convert it to int OR use totalhours as Int variable(with.tostring) and then your 6 hours should again needs to converted to int and then use it in the IF Condition…
Thank you,Like you said, Can I try this in If condition: Cint(RunningTime)> Cint(ConstantTime)?
where Running Time is the Total running hours of Type String , ConstantTime is the 06:00 of type string
I am able to Understand now, I am implementing it but for some reason, it is running slowly, I will let you know it sooner. Thank you so much for your spontenious response!
I tried by setting all 3 variables as String and tried your statement to subtract and that worked as well. Thank you so much. But since I need totalHours calculation, I used " (CurrentTime.subtract(StartTime).totalhours).toString.
Thank you so much!
@prasath17 I wanted to compare the dates by getting the date (MM/dd/yyyy HH:mm:ss) from an excel file and comparing it with today’s date.
I am getting it by using : StrTime = row.item(“StartTime”).toString.trim() and then for converting to Datetime, I used( StartTime=datetime.ParseExact(Strtime,“MM/dd/yyyy HH:mm:ss”,system.Globilization.CultureInfo.InvariantCulture) .
For comparing , did : datetime.ParseExact(Strtime,“MM/dd/yyyy HH:mm:ss”,system.Globilization.DateTimeFormatInfo.InvariantInfo)= Today
I end up getting error: String was not recognised as valid date time error.