Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • %d is Day of the month as a zero-padded decimal number. 01, 02, …, 31

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

like image 588
Stéphane GRILLON Avatar asked Oct 26 '25 00:10

Stéphane GRILLON


1 Answers

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
like image 97
Würgspaß Avatar answered Oct 29 '25 10:10

Würgspaß



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!