473,396 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Day of Year Behaviour

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
Jul 18 '05 #1
2 1473
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
Jul 18 '05 #2
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.
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the...
2
by: Oly | last post by:
give your opinions concerning our site,end work first year web technology www.zwin.tk in java: -navigation -stylechanger (with cookie) -pamorama -gallery
1
by: Kejpa | last post by:
Hi, I've bumped into some strange behaviour when trying to set the localization of my app. I want it to have Monday as the first day of week and the first 4 day-week as week # 1. However, Jan...
0
by: Panayotis Kouvarakis | last post by:
I have noticed that CompareValidator and RangeValidator don't work properly with 2-digit year dates when using client script validation. Specifically the problem lies in the way the string is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.