3

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

Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154
  • Possible duplicate of [Python datetime formatting without zero-padding](https://stackoverflow.com/questions/9525944/python-datetime-formatting-without-zero-padding) – Todor Minakov Apr 01 '19 at 08:53
  • @TodorMinakov, No, my question is on the day of the month not on the month number. Please revove duplucate tag. – Stéphane GRILLON Apr 01 '19 at 09:10
  • It's the same, is it the day of the month or the month number - simple string manipulation. – Todor Minakov Apr 01 '19 at 09:33
  • 1
    Your question is - how to remove the 0-padding of dates produced by `strftime()`; the linked question has numerous answers, some good, some less so. Thus I marked it as a duplicate. "Würgspaß find the solution, not you." I'm truly happy for him, thus he got my upvote ¯\\_(ツ)_/¯. And in the same time, I find the tone of your message inappropriate. – Todor Minakov Apr 01 '19 at 09:49
  • @TodorMinakov, my question is not "how to remove the 0-padding of dates produced by strftime();" is it "**Day of the month** without zero-padded decimal number" – Stéphane GRILLON Apr 01 '19 at 09:54

2 Answers2

4

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
Würgspaß
  • 4,660
  • 2
  • 25
  • 41
0

You can use '#' during format to ignore 0's e.g.

${today}=  Get Time

${today_formated}=  Convert Date  ${today}  result_format=%#d
Dalip Kumar
  • 71
  • 1
  • 1
  • 6