9 ms·
Cool project. I'm a bit reluctant to trust the quality of this, however. The first example I looked up was "Format date YYYY-MM-DD" in Python, which wanted me
by markild 7y ago
Cool project.
I'm a bit reluctant to trust the quality of this, however.
The first example I looked up was "Format date YYYY-MM-DD" in Python, which wanted me to use "isoformat()", which produces something else.
It was easy to correct, but I'd like to see a more "democratic" approach to getting correct examples, not just taking the latest one as fact.
edit: Sorry, more precise critique of the usage of "isoformat" would be "which _might_ produce something else" (it depends on the resolution of info in the date object).
- jessedhillon 7y agoisoformat() formats date objects into dates of ISO-8601 format (YYYY-mm-dd). It formats datetimes into something extra.
- dwringer 7y agoWhen I view that page[1] I see two different techniques listed, isoformat() being the second. The first is to use d.strftime('%Y-%m-%d'). In regard to the second, isoformat on a "datetime" will give increased resolution beyond "YYYY-MM-DD", but a "date" object only resolves year, month and day and such a call will indeed yield the correct output (per the linked documentation at [2]). [1] https://www.programming-idioms.org/idiom/99/format-date-yyyy-mm-dd/1429/python https://www.programming-idioms.org/idiom/99/format-date-yyyy... [2] https://docs.python.org/3/library/datetime.html#datetime.date.isoformat https://docs.python.org/3/library/datetime.html#datetime.dat...
- i_cant_speel 7y agoIt sounds like the person you responded to corrected it themselves.
- perfunctory 7y ago> "which _might_ produce something else" (it depends on the resolution of info in the date object). I am not sure what you mean by "the resolution of info in the date object". Can you clarify?
- colejohnson66 7y agoIf the date object only stores up to the day, then you can only format the string up to the day. If it stores up to the second, you can format up to the second
- perfunctory 7y agoPython’s date object does not store seconds.
- colejohnson66 7y agoI am aware. I was simply explaining what is meant by “resolution.”
- blaze33 7y agoI just did a google search for "Format date YYYY-MM-DD in Python", clicked the first link to stackoverflow and got several answers, 1st says `.strftime('%Y-%m-%d')`, 2nd `str(date.today())` and using `isoformat` is the 4th answer. I guess I'm not the only dev who would do the same in case I actually wanted to check how to correctly format a date in Python: ctrl+t, type, type, enter, click, read, read, ctrl+c, ctr+v and done. That's the competition for programming-idioms.org if you ask me. > I'd like to see a more "democratic" approach to getting correct examples Me too! Stackoverflow contributions are cc-licensed so maybe a tool to easily curate answers to classic issues and build on top of them would work well. I'm not sure crowdsourcing programming idioms from scratch would be the easiest way to go as I feel the work is mostly halfway done out there (but sure could use some curation). Actually now that I think about it, that's related to what stackoverflow tried to do with their documentation by examples attempt (cf. https://meta.stackoverflow.com/questions/354217/sunsetting-documentation https://meta.stackoverflow.com/questions/354217/sunsetting-d...).