You want to get classmethod datetime.datetime.strptime() , then take the .days attribute from received timedelta:
import datetime mdate = "2010-10-05" rdate = "2010-10-05" mdate1 = datetime.datetime.strptime(mdate, "%Y-%m-%d").date() rdate1 = datetime.datetime.strptime(rdate, "%Y-%m-%d").date() delta = (mdate1 - rdate1).days
So, you have a datetime module that has a datetime.datetime class, which in turn has a datetime.datetime.strptime() method on it. I also added calls to .date() to extract only a portion of the date (the result is an instance of datetime.date ); this allows you to cope with timestamps that differ by a little less than 24 hours.
Demo:
>>> import datetime >>> mdate = "2010-10-05" >>> rdate = "2010-10-05" >>> mdate1 = datetime.datetime.strptime(mdate, "%Y-%m-%d").date() >>> rdate1 = datetime.datetime.strptime(rdate, "%Y-%m-%d").date() >>> delta = (mdate1 - rdate1).days >>> print delta 0 >>> type(delta) <type 'int'>
source share