Day of Year Behaviour

Discussion in 'Python' started by Hector Villafuerte, Sep 30, 2004.

  1. 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:
    >>> time.localtime(time.mktime((2004, 0, 0, 0, 0, 0, 0, 1, 0)))

    (2003, 11, 30, 0, 0, 0, 6, 334, 0)

    Any suggestions? Thanks in advance!
    Hector Villafuerte
     
    Hector Villafuerte, Sep 30, 2004
    #1
    1. Advertising

  2. On 30 Sep 2004 15:55:53 -0700, Hector Villafuerte wrote:

    >
    > I'm using the time module without success:
    >>>> time.localtime(time.mktime((2004, 0, 0, 0, 0, 0, 0, 1, 0)))

    > (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:

    >>> time.localtime(time.mktime((2004, 1, 1, 0, 0, 0, 0, 0, 0)))

    (2004, 1, 1, 0, 0, 0, 3, 1, 0)
    >>> time.localtime(time.mktime((2004, 1, 33, 0, 0, 0, 0, 0, 0)))

    (2004, 2, 2, 0, 0, 0, 0, 33, 0)
    >>> time.localtime(time.mktime((2004, 1, 365, 0, 0, 0, 0, 0, 0)))

    (2004, 12, 30, 0, 0, 0, 3, 365, 0)
    >>>


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

    --
    Richard
     
    Richard Townsend, Oct 1, 2004
    #2
    1. Advertising

  3. 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.


    > 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:
    > >>> time.localtime(time.mktime((2004, 0, 0, 0, 0, 0, 0, 1, 0)))

    >
    > (2003, 11, 30, 0, 0, 0, 6, 334, 0)
    >
    > Any suggestions? Thanks in advance!
    > Hector Villafuerte


    --
    Gerardo Herzig
    Departamento de Proyectos Especiales e Internet
    Facultad de Medicina
    U.B.A.
     
    Gerardo Herzig -Departamento de Proyectos Especial, Oct 1, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Otuatail

    Week of year to full Year

    Otuatail, Dec 8, 2003, in forum: HTML
    Replies:
    4
    Views:
    981
    Toby A Inkster
    Dec 8, 2003
  2. Robert Brewer

    RE: Day of Year Behaviour

    Robert Brewer, Oct 1, 2004, in forum: Python
    Replies:
    1
    Views:
    338
    Anna Martelli Ravenscroft
    Oct 1, 2004
  3. Andy
    Replies:
    1
    Views:
    743
  4. Rob Redmon

    Convert day of year to month, day

    Rob Redmon, Apr 4, 2008, in forum: Ruby
    Replies:
    7
    Views:
    324
    Alex Wayne
    Apr 4, 2008
  5. Veerle
    Replies:
    2
    Views:
    428
    niceguy
    Aug 20, 2003
Loading...

Share This Page