'RobotFramework: How to convert date to lose leading zeros from single digit days

See below. From checking dateformats, the %d should work but doesnt seem to - see output.

Log to console  Completion Date ${completion_date}
${date_to_search_for}=  Convert Date  ${completion_date}  date_format=%Y-%m-%d %H:%m:%S.%f  result_format=%d %b %Y 00:00:00  exclude_millis=True
Log to console  Completion Date ${date_to_search_for}

Outputs for ${completion_date}

Completion Date 2017-07-01 08:37:13.656083

Outputs for ${date_to_search_for}

Completion Date 01 Jul 2017 00:00:00


Solution 1:[1]

As far as I can tell from the documentation %dworks exactly as described in the example in the documentation for a Custom Timestamp.

For your desired effect please have a look at the Python datetime example:

${datetime} =   Convert Date    2014-06-11 10:07:42.123 datetime
Should Be Equal As Integers    ${datetime.year}      2014   
Should Be Equal As Integers    ${datetime.month}         6  
Should Be Equal As Integers    ${datetime.day}           11 
Should Be Equal As Integers    ${datetime.hour}      10 
Should Be Equal As Integers    ${datetime.minute}        7  
Should Be Equal As Integers    ${datetime.second}        42 
Should Be Equal As Integers    ${datetime.microsecond}  123000

Solution 2:[2]

a_date = datetime.date(2005, 7, 14)
string_date = a_date.strftime("%-m/%-d/%Y")
Replace "-" with "#" if using Windows

print(string_date)

OUTPUT

7/14/2005

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 A. Kootstra
Solution 2 Jeremy Caney