Light Mode
Dark Mode
Why do I get a ValueError

My current code raises following error:

return convert.strftime("%-d %B %Y year %-H {hour} %-M {minute}") ValueError: Invalid format string

My Code:

def date_time(time_input: str) -> str:
    hour = "hours"
    minute = "minutes"

    convert = datetime.datetime.strptime(time_input, "%d.%m.%Y %H:%M")
    if convert.hour == 1:
        hour = "hour"
    if convert.minute == 1:
        minute = "minute"

    return convert.strftime(f"%-d %B %Y year %-H {hour} %-M {minute}")

But why ?!

Created: Sept. 20, 2020, 6:11 p.m.
Updated: Sept. 23, 2020, 3:33 p.m.
1
9
User avatar
Jonethan