Date/Time format

4,221 views
Skip to first unread message

finspin

unread,
Aug 20, 2012, 4:33:51 AM8/20/12
to robotframe...@googlegroups.com
Is there an easy way to generate current date in the following format DD/MM/YYYY?

To my understanding the built in Get Time keyword doesn't support this kind of formatting.

Mikko Korpela

unread,
Aug 20, 2012, 5:23:37 AM8/20/12
to jaros...@gmail.com, robotframe...@googlegroups.com
Hi,

Although the "BuiltIn.Get Time" is partly kind of confusing keyword it
can be used to achieve what you want:

*** Keywords ***
times
${foo}= Get Time year month day
${bar}= Set Variable ${foo[2]}/${foo[1]}/${foo[0]}

You could of course make your own python/java keyword that does the same trick.

Kind Regards,
Mikko Korpela

2012/8/20 finspin <jaros...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "robotframework-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/robotframework-users/-/IPyz1EcY1YUJ.
> To post to this group, send email to robotframe...@googlegroups.com.
> To unsubscribe from this group, send email to
> robotframework-u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/robotframework-users?hl=en.

finspin

unread,
Aug 20, 2012, 6:49:24 AM8/20/12
to robotframe...@googlegroups.com
Fantastic! I didn't think of using the keyword that way. Thanks!


On Monday, 20 August 2012 12:23:37 UTC+3, Mikko Korpela wrote:
Hi,

Although the "BuiltIn.Get Time" is partly kind of confusing keyword it
can be used to achieve what you want:

*** Keywords ***
times
    ${foo}=    Get Time    year month day
    ${bar}=    Set Variable    ${foo[2]}/${foo[1]}/${foo[0]}

You could of course make your own python/java keyword that does the same trick.

Kind Regards,
Mikko Korpela

2012/8/20 finspin <jaros...@gmail.com>:
> Is there an easy way to generate current date in the following format
> DD/MM/YYYY?
>
> To my understanding the built in Get Time keyword doesn't support this kind
> of formatting.
>
> --
> You received this message because you are subscribed to the Google Groups
> "robotframework-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/robotframework-users/-/IPyz1EcY1YUJ.
> To post to this group, send email to robotframe...@googlegroups.com.
> To unsubscribe from this group, send email to
> robotframework-users+unsub...@googlegroups.com.

Kevin O.

unread,
Aug 20, 2012, 2:36:40 PM8/20/12
to robotframe...@googlegroups.com
Here's yet another way of doing it
    ${yyyy}    ${mm}    ${dd}    Get Time    year,month,day
    ${date}    Set Variable    ${dd}/${mm}/${yyyy}


sudip pudasaini

unread,
Jun 15, 2015, 2:04:20 AM6/15/15
to robotframe...@googlegroups.com
What could be the better way to convert mm-dd-yyyy date format to either yyyy-mm-dd or dd-mm-yyyy? I have tried several ways but could not find the solution. Can you guys suggest me the way to resolve this problem?

Trey Duskin

unread,
Jun 15, 2015, 9:46:08 AM6/15/15
to robotframe...@googlegroups.com
I have a library that I started a while ago to help improve date & time manipulations in RF.  I don't know if it will give you what you want but it might be a start: https://github.com/tduskin/robotframework-datetimelibrary

Ben Fariello

unread,
Jun 15, 2015, 10:46:54 PM6/15/15
to robotframe...@googlegroups.com
I had just shared this with one of my coworkers last Thursday. Try the (built-in) DateTime library. Specifically, you can use this:


and specify date_format (for the input) and result_format (the desired format of the output). Try something like this:

*** Settings ***
Library    DateTime


*** Test Cases ***

Give Me Days
    ${today} =         Get Current Date    result_format=%Y-%m-%d
Should Be Equal    ${today}    2015-06-15
    #result_format=%Y-%m-%d gives you, for example, 2015-06-15
    ${converted} =     Convert Date    ${today}    date_format=%Y-%m-%d    result_format=%m-%d-%y
Should Be Equal    ${converted}    06-15-15
#%m-%d-%y will give you 06-15-15 ---- note that %Y is the four-digit year and %y is the two-digit year! That matters.

Pardon the Retina screen (i.e. giant screenshot) but you can see here that when this test case runs, it passes. http://i.imgur.com/gRRFhRk.png

On Monday, June 15, 2015 at 2:04:20 AM UTC-4, sudip pudasaini wrote:

Ben Fariello

unread,
Jun 15, 2015, 10:49:56 PM6/15/15
to robotframe...@googlegroups.com
Note: I accidentally dropped the "BuiltIn" library from this example, so you'll have to include that too (for the Should Be Equal keyword). I tacked this test case on to a Suite I'd already written for simplicity's sake, and ripped out everything but the case, and added in the parts I thought I needed.

Nick Shaw

unread,
Jun 17, 2015, 6:56:34 AM6/17/15
to robotframe...@googlegroups.com
I can second Ben's advice here, this is how I solved the same issue.

Dmitry Boyko

unread,
Oct 31, 2015, 11:58:02 AM10/31/15
to robotframework-users
Thank you for sharing your code..
It works perfectly in my case.
Could you please help me increase usability of this method?
I need have possibility add to text fields date yesterday and tommorow.
How I can do that?
Thank you for you passion.

Tatu Aalto

unread,
Oct 31, 2015, 3:06:16 PM10/31/15
to 8184160...@gmail.com, robotframework-users

Ugh

Answer to that question is explained in the keyword documentation: http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Get%20Time

-Tatu
Send from my mobile

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.

To post to this group, send email to robotframe...@googlegroups.com.

anna...@directpl.com

unread,
Oct 28, 2016, 10:43:01 AM10/28/16
to robotframework-users
I have a different question:
How can I in RF convert time from 12-hour (AM and PM) into 24-hour and inversely?

Kevin O.

unread,
Nov 1, 2016, 1:40:07 AM11/1/16
to robotframework-users
Reply all
Reply to author
Forward
0 new messages