Day of Year Behaviour

H

Hector Villafuerte

Hi all!
I have 2 fields:
YEAR
DAY_OF_YEAR

and I need to get the complete date out of this, e.g.:
YEAR=2004
DAY_OF_YEAR=1
-> DATE=2004/Jan/1

YEAR=2004
DAY_OF_YEAR=33
-> DATE=2004/Feb/2

I'm using the time module without success:(2003, 11, 30, 0, 0, 0, 6, 334, 0)

Any suggestions? Thanks in advance!
Hector Villafuerte
 
R

Richard Townsend

I'm using the time module without success:
(2003, 11, 30, 0, 0, 0, 6, 334, 0)

If you pass the year-day as the third item in the 9-tuple, then
localtime(mktime()) should normalise the date correctly:

But, as others have stated, the datetime module is probably the better way
to go.
 
G

Gerardo Herzig -Departamento de Proyectos Especial

well, normalDate will help you here. I think normalDate is not in python
standart ditribution, but it is a pretty nice peace or work.

YEAR = 2004
DAY_OF_YEAR = 40
import normalDate
date = normalDate.ND('%s0101' % YEAR) + DAY_OF_YEAR
print date.formatUS()
-> '02/10/04'
normalDate have more methods (most of them are simple formateed prints)

Gerardo.
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top