Calendar yr-mnth-day data to day since data

Piet van Oostrum piet at cs.uu.nl
Sat Oct 3 12:35:55 CEST 2009


>>>>> "skorpio11 at gmail.com" <skorpio11 at gmail.com> (sc) wrote:

>sc> Hi all,
>sc> I have some calendar data in three arrays corresponding to yr, month,
>sc> day that I would like to convert to day since data and be consistent
>sc> with changes in leap year. I've included a sample of the data
>sc> structures below.  Any suggestions???  Thanks in advance

>sc> yr          mnth            day                 daySince
>sc> 1970    1                       1                     1
>sc> 1970    1                       15                  15
>sc> 1970    1                       28                  28
>sc> 1970    2                       1
>sc> 32
>sc> 1970    2                       27                  59
>sc> 1970    3                       1
>sc> 1970    3                       4
>sc> 1970    3                       29
>sc>     ...       ...                        ...

>sc> 2008    1                       1
>sc> 2008    1                       8
>sc> 2008    1                       25
>sc> 2008    2                       1

Days since what? It appears here to be since 1969-12-31, or since
1970-1-1 but then starting with 1 instead of 0.
And your 59 is wrong if the others are deemed to be correct.

Depending on what you want you have to add 1 to the following solution

import datetime
startdate = datetime.date(1970, 1, 1)
enddate = datetime.date(1970,3,1)
timediff = enddate - startdate
print timediff.days

result: 59
-- 
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]



More information about the Python-list mailing list