robotframework

Robotframework - Day of the month without zero-padded decimal number


I use this:

${today}=  Get Time
${today_formated}=  Convert Date  ${today}  result_format=%d

The result is 01 for the 1st day of the month but I need 1.

How to remove 0 at the start?

My question is on the day of the month not on the month number

full robotframework script:

*** Settings ***
Library    SeleniumLibrary
Library    DateTime

*** Keywords ***
test
    ${today}=           Get Time
    ${today_formated}=  Convert Date      ${today}  result_format=%d
    Log To Console  ${today_formated}

*** Test Cases ***

PLFT
    [Tags]  foo|AC0
    Given test

01


Solution

  • Use Replace String Using Regexp from standard library String

    ${today}=  Get Time
    ${today_formated}=  Convert Date  ${today}  result_format=%d
    ${today_no_padding}=    Replace String Using Regexp    ${today_formated}    ^0    ${EMPTY} 
    

    This transforms values with leading zeros like 01 to 1 but values just containing zeros like 10 would remain the same.

    To use the library, add a declaration to your settings:

    *** Settings ***
        Library    SeleniumLibrary
        Library    DateTime
        Library    String