Python dates

From Noah.org
Revision as of 19:19, 27 February 2008 by Root (talk | contribs) (New page: Category:Engineering Category:Python Python has built-in support for doing date arithmetic. Here are some samples: <pre> import time, datetime year = '2008' month = '1' day = '24'...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Python has built-in support for doing date arithmetic. Here are some samples:

import time, datetime

year = '2008'
month = '1'
day = '24'

last_month = datetime.datetime.now() - datetime.timedelta(days=32)
now = datetime.datetime.now()
other_date = datetime.datetime(year=int(year), month=int(month), day=int(day))
if (now - other_date).days > 31:
    print "Older than a month."