Adding multiples of a time interval to a date-time

461 views
Skip to first unread message

crater...@gmail.com

unread,
Dec 13, 2016, 6:18:16 AM12/13/16
to robotframework-users
Hello,
I can't figure a good way to deal with adding multiple of some time interval to a date. To be more precise...
Let's say I have a ${present_time} variable, which holds a date-time. To this variable I would like to add, e.g. X times 10 minutes, where X is an arbitrary integer. So I can get eg. present time + 50 minutes later.
Can you help me with some tips on how to do it?
Thank you, JC

Jaakko Salminen

unread,
Dec 13, 2016, 6:42:57 AM12/13/16
to robotframework-users
Hi,

DateTime library has some really good stuff for handling time related operations: http://robotframework.org/robotframework/latest/libraries/DateTime.html

So for example:
${x}=  Set Variable  5
${date}=  Get Current Date
${increment}=  Evaluate  ${x} * 10
${date}=  Add Time To Date  ${date}  ${increment} minutes

crater...@gmail.com

unread,
Dec 13, 2016, 6:50:56 AM12/13/16
to robotframe...@googlegroups.com
Thank you for your reply Jaakko. I was thinking about something pretty similar to what you proposed. My problem is that the variable you set as 10 is not an integer in my case, but a time, e.g. 10 minutes. So put in other words, I would like to multiply 5*10 minutes, and then do the Add Time To Date as you showed.


Dne torek, 13. december 2016 12.18.16 UTC+1 je oseba crater...@gmail.com napisala:

Jaakko Salminen

unread,
Dec 13, 2016, 7:11:27 AM12/13/16
to robotframework-users
I think you can still multiply it, result will be in seconds so that must be taken into account before adding:

  ${x}=  Set Variable  5
  ${time}=  Convert Time  10 minutes
  ${date}=  Get Current Date
  ${increment}=  Evaluate  ${x} * ${time}
  ${date}=  Add Time To Date  ${date}  ${increment} seconds


crater...@gmail.com

unread,
Dec 13, 2016, 7:19:46 AM12/13/16
to robotframework-users
Blimey it really does work, I've no idea what I was doing to keep getting all kinds of errors. I suppose I missed that "Convert Time". Also I see Get Current Date has optional "increment" parameter, which is perfect for what I need. Thanks a lot! 


Dne torek, 13. december 2016 13.11.27 UTC+1 je oseba Jaakko Salminen napisala:
Reply all
Reply to author
Forward
0 new messages