find difference in days from YYYYMMDD to YYYYMMDD

chaelon at gmail.com chaelon at gmail.com
Sat Sep 22 21:09:01 EDT 2007


On Sep 22, 5:37 am, Konstantinos Pachopoulos <kostaspa... at yahoo.gr>
wrote:
> Hi,
> does any body now any such algorith? to find difference in days from
> YYYYMMDD to YYYYMMDD?
> Or just an algorithm, that converts YYYYMMDD to seconds since the epoch?
>
> Thanks

Seen some complex answers here.  Let's keep it dead simple.  Use the
datetime module to do the heavy lifting.  Go to IDLE, write this.

import datetime.

Then start to write this:

difference = datetime.date(

and at that point IDLE will tell you to put in year,month,day.  That's
convenient.  Do as IDLE asks, obey IDLE!  Wind up with this (put date
later in history first, here are two I've used):

difference = datetime.date(2007,9,25) - datetime.date(1970,12,25)
print difference

13419 days, 0:00:00

Hey now!  Date math!  Yeah!




More information about the Python-list mailing list