Home > other >  Problem with changing date to format DMMYYYY in Python
Problem with changing date to format DMMYYYY in Python

Time:11-19

I have a problem with changing date format to e.g. 9November2021 but not 09November2021.

d = date(2021, 11, 9)

I tried to do it this way: d.strftime('%-d%B%Y') but although it seems to be working on my personal laptop with MacOS, when I try to run it on my work laptop with Windows I get a ValueError: Invalid format string.

I would really appreciate your help.

CodePudding user response:

You have to use # on Windows instead of -

so instead of d.strftime('%-d%B%Y')
Try this d.strftime('%#d%B%Y')

CodePudding user response:

This is a great web page for all your formatting needs: https://strftime.org

I believe instead of a "-", you will want to use a "#" on Windows. If you are still having issues, another solution is suggested here: https://github.com/evennia/evennia/issues/1881 -- they suggest using "{dtobj.day}" instead of "-d".

Have a wonderful day!

  • Related