Tag Archives: datetime

Python datetime quiz

Without looking at the documentation (or running the code), describe the outputs of the following 4 function calls: from datetime import datetime datetime.datetime.now() datetime.datetime.today() datetime.datetime.now().date() datetime.datetime.today().date() Post your answers as a comment.

Posted in General | Tagged , | 3 Comments

summing datetime.timedelta objects in Python

Argh! The following snippet is totally broken: import datetime times = [datetime.timedelta(hours=1), datetime.timedelta(minutes=30)] print sum(times) print min(times) print max(times) It raises “TypeError: unsupported operand type(s) for +: ‘int’ and ‘datetime.timedelta’” The thing is, I want this function to be able … Continue reading

Posted in General | Tagged , , | Leave a comment