DateTime comparison

Hi , I want to compare between two different times. like the difference between them is less than fifteen mintues or not. So is there any way to do that?

Hi @sonali_parida. Do you need to compare only time without date?

@Lera I want to compare with date too.

So, I suggest to use If-Else Condition to compare dates.
Important note: to compare dates with time stamp you need to use the same time format. If your dates have different format, you need to convert them to have similar format. I attach short example with dates comparison below.
DateTime_comparison.zip (1.1 KB)

@Lera what i am going through is , i am capturing a date from a window using abby screenshot(so it is coming in a string format) and i have to compare it with the current date and time of my system which is coming in a date format. So i want two know if these two time has a 15 minute difference in between them or not? Because every time i am trying to convert the string into date format it is showing error.

Can you please share the error message or send full stack trace?

Error executing DateFormatAction
com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=DateFormatAction.ftl,id=4,name=Optional[DateFormatAction],parent=1,nextSibling=5,arguments=ActionArguments[outputLocale=[en],outputMask=[dd/MM/yy],inputLocale=[en],xsi:type=[recorder:DateFormatAction, recorder:DateFormatAction],pollingInterval=[300],active=[true],inputMask=[dd/MM/yyyy],input=[${c}],targetVariable=[c],delay=[0],timeoutMs=[10000],awaitTimeout=[5000],direction=[STRING_TO_STRING]]]
at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:54)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.time.format.DateTimeParseException: Text ‘13/8/2019’ could not be parsed at index 3
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parseBest(DateTimeFormatter.java:1897)
at com.workfusion.studio.rpa.recorder.api.internal.representation.RDateTimeRepresentation$CustomRepresentation.parse(RDateTimeRepresentation.java:140)
at com.workfusion.studio.rpa.recorder.api.internal.representation.RDateTimeRepresentation.getValue(RDateTimeRepresentation.java:53)
at com.workfusion.studio.rpa.recorder.api.types.RDateTime.fromRepresentation(RDateTime.java:104)
at com.workfusion.studio.rpa.recorder.api.types.RDateTime$fromRepresentation.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
at Script5.run(Script5.groovy:8)
at com.workfusion.studio.rpa.recorder.playback.shell.GroovyShellWrapper.executeScript(GroovyShellWrapper.java:48)
at com.workfusion.studio.rpa.recorder.playback.player.PlaybackContext.executeScript(PlaybackContext.java:108)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.executeBehavior(TemplateAction.java:33)
at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:46)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
at java.lang.Thread.run(Thread.java:745)

Looks like format issue. Please try to change date format in Format option to dd/M/yyyy - I see that you use different format - dd/MM/yyyy with double M.

@Lera Just tried and it did not show any error. Thanks for the solution.
But how can i compare if they have 15 mintues difference in between them or not? Do i have to convert the whole time in to second and then substitute? there’s no direct way?

Thanks, understood. So in your case, maybe custom script will be more useful to check time difference between 2 dates.

1 Like

okay . i’ll give it a try.

2 Likes

Thank you. If you find a solution for your case, could you please post it there if possible?

1 Like

Yeah Sure. I’ll update when i’ll get the solutions.

2 Likes