question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid format string %04Y on Windows

See original GitHub issue

Invalid format string when using %04Y on Windows 10 Python 3.7.1

$ python
>>> from datetime import datetime
>>> datetime(90, 1, 1).strftime("%04Y")
ValueError: Invalid format string
>>> datetime.strptime("2018-10-31 22:29:29.553000", "%Y-%m-%d %H:%M:%S.%f").strftime("%04Y-%m-%dT%H:%M:%S.%fZ")
ValueError: Invalid format string

Some platforms support modifiers from POSIX 2008 (and others). On Linux the format “%04Y” assures a minimum of four characters and zero-padding. The internal code (as used on Windows and by default on macOS) uses zero-padding by default

https://www.rdocumentation.org/packages/base/versions/3.5.1/topics/strptime#l_sections


Related issues

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
timvishercommented, Oct 31, 2018

Pushed 5.3.3 to PyPI. Thanks! 😃

1reaction
timvishercommented, Oct 31, 2018

Ah. Got it. 😃

So we’d definitely accept patches to improve Windows support but I’ll let you know up front that the testing burden might be a little high, since none of us have easy access to Windows machines at the moment nor any expertise on developing/debugging Python on Windows issues.

I guess at a minimum we’ll want to see some unit tests added if they don’t already exist that test that 3 digit years are zero padded without %04D on Windows and that they continue to be padded on Mac/Linux.

In terms of the general design I don’t think duck typing is necessarily the wrong way to go here. First try with the Mac/Linux format string, fall back to the windows format string on an exception, otherwise raise.

Sound good?

Read more comments on GitHub >

github_iconTop Results From Across the Web

String.Format Method (System) - Microsoft Learn
Converts the value of objects to strings based on the formats specified and inserts them into another string. If you are new to...
Read more >
Invalid Format Specification: '%' - TechNet - Microsoft
I am receiving an sql exception of "Invalid Format Specification: ... select @string = 'error in my table %1! into my database %2!';...
Read more >
FormatException Class (System) - Microsoft Learn
The exception that is thrown when the format of an argument is invalid, or when a composite format string is not well formed....
Read more >
String wrong format error - Power Platform Community
I'm creating a Realdatatime that conects Forms+Flow (Power Automate)+ PowerBI. As user answer forms the dashboards are updated in PowerBI, but i ...
Read more >
Strings.Format(Object, String) Method (Microsoft.VisualBasic)
Returns a string formatted according to instructions contained in a format ... Dim testDateTime As Date = #1/27/2001 5:04:23 PM# Dim testStr As...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found