find difference in days from YYYYMMDD to YYYYMMDD
tokland at gmail.com
tokland at gmail.com
Sat Sep 22 11:04:19 EDT 2007
On 22 sep, 11:37, Konstantinos Pachopoulos <kostaspa... at yahoo.gr>
wrote:
> does any body now any such algorith? to find difference in days from
> YYYYMMDD to YYYYMMDD?
Once I needed the same and I wrote:
def days_difference(s1, s2):
splitdate = lambda s: time.strptime(s, "%Y%m%d")[:3]
str2date = lambda s: datetime.date(*splitdate(s))
delta = str2date(s1) - str2date(s2)
return delta.days
print days_difference("20071112", "20061029") # 379
Although I'm sure there is a better way.
arnau
More information about the Python-list
mailing list