Calendar yr-mnth-day data to day since data

S

skorpio11

Hi all,

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

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

2008 1 1
2008 1 8
2008 1 25
2008 2 1
 
P

Piet van Oostrum

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
 
S

skorpio11

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

Thanks ... This module does the trick nicely
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top