days between dates

Seems like finding out days between dates is not a trivial task. There is quite a bit of support in tools for adding up dates, but literally none for evaluating the difference. Unix systems return time using epoch as reference, thus you need to divide the difference by 86400 (#seconds in a day) to get the #days. However I wanted something portable that would work across all platforms without me having to worry about leap-years and such esoteric stuff.

The obvious choice then became python (a bit more readable compared to shell scripts). Anyway here is the python script to give you the days between dates using date object:

1
2
3
4
5
6
7
from datetime import date
# add 1 to account for today as well
# 1982 days ago I started my blog (first post on 4 Jan 2009)
# Note: do not to add 0 in front of 1 or 4 (Month or Day)
# seems like python hates it that way..
#
(date.today() - date(2009, 1, 4)).days + 1