Python – Just a bit about datetime and timedelta

Ok, dates in VBA and Excel are somehow complicated, because of some “feature” that Microsoft Excel has introduced, due to compatibility issues. I have already wrote a few articles about these here, and separate one about what day is Friday in the week of a given date here, and how to use NetworkDays with Dateserial in Excel here. Fortunately, this is not the case with Python, where the benevolent dictator would not have allowed it (or at least we all hope so).

On the sea it is always Saturday, but in Sofia it seems that Mondays are endless…

The idea of this article is simply to show some code, that will produce well formatted strings from a date, that will save me a few clicks in google, every time I need to implement it:

The only thing that is worth mentioning is probably the beautiful application of timedelta, that can solve some possible problems if you might have, when you need to add or remove some time period. The rest is probably self-explanatory.

Enjoy it!

Tagged with: , , ,