1

I was googling for 'Python convert German date to day of week'. Since I could not find anything I wrote my own script to convert a date like this:

"04.07.2016" -> 0 (Monday)
"05.07.2016" -> 1 (Tuesday)
 ...
"10.07.2016" -> 6 (Sunday)
 ...
"17.07.2016" -> 6 (Sunday)

Since this could be useful for other folks, I would like to post this somewhere so it can be easily found (I might also need this again in the future).

4
  • 5
    You could ask a self-answered question, but for this one I'd stick to library functions... Commented Jul 5, 2016 at 14:56
  • Was your script anything like this? which day of week given a date python - (found by using your own search term minus the "german")
    – Sayse
    Commented Jul 5, 2016 at 14:59
  • @Jan Dvorak Ok good idea. I do stick to library functions... ;-)
    – Ohumeronen
    Commented Jul 5, 2016 at 14:59
  • @user2177047 a small code snippet to help you ideone.com/HhQmTs Commented Jul 5, 2016 at 15:03

2 Answers 2

3

You could ask a canonical self-answered question, which is basically a "fake" question with a presupplied answer. The question would be something like "How can I get the day of the week from a date?", and the answer would be your script -- included entirely in the answer -- with an explanation of what it does, its constraints, etc. The benefits of this approach are that if someone has a better solution, they can post it. I'd suggest not accepting your own answer for at least a couple of days, to encourage other people to contribute.

Before doing this, make sure to check for any preexisting canonical questions, or yours will get closed as a dupe. Search well. If you find nothing that's similar, post it as your own Q&A pair.

[NB: This question is highly related. Before you post your own, make sure that it doesn't answer that question; if it does, post it as an answer there.]

You'll also want to make sure that your solution is as bugfree as possible.

2
  • Thank you, nice to know that now.
    – Ohumeronen
    Commented Jul 5, 2016 at 15:04
  • @user2177047 You're very welcome! I'm a bit miffed that I couldn't find the question that this was eventually closed as a dupe of, though; I'd have closed as duplicate otherwise.
    – Nic
    Commented Jul 5, 2016 at 15:08
0

Another place to post something like this would be Documentation, which will be launching very soon.

Documentation (Which is currently in private beta), is very much focused on individual code examples (or "mini tutorials"), and editing by the community, so I think Docs.SO be a good place to post a code snippet for this, once it launces publicly.

1
  • Thanks! I will check it out if I need something like that again.
    – Ohumeronen
    Commented Jul 6, 2016 at 16:50

Not the answer you're looking for? Browse other questions tagged .