This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fractional day attribute in datetime class
Type: enhancement Stage: resolved
Components: Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: Miguel.de.Val.Borro, belopolsky, daniel.urban
Priority: normal Keywords:

Created on 2011-08-17 16:15 by Miguel.de.Val.Borro, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg142286 - (view) Author: Miguel de Val Borro (Miguel.de.Val.Borro) Date: 2011-08-17 16:15
It would be useful to have a fractional day method in datetime.datetime
that returns a float object calculated from the day, hour, minute, second, and microseconds. Fractional days in UTC are often used in science, in particular to record astronomical observations.
msg142503 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-08-19 22:53
You can easily get the fractional day value using existing functionality:


>>> from datetime import *
>>> (datetime(2011,8,15,18,30) -  datetime(2011,8,13,12,0)) / timedelta(1)
2.2708333333333335
>>> (datetime(2011,8,15,18,30) -  datetime(1970,1,1)) / timedelta(1)
15201.770833333334

In some sense this request is a duplicate of issue2736.
msg142553 - (view) Author: Miguel de Val Borro (Miguel.de.Val.Borro) Date: 2011-08-20 18:49
Thanks, I need the fractional day added to the ordinal day of the month. Using the timedelta division it would be:

>>> from __future__ import division
>>> dt = datetime.datetime(2008, 5, 8, 13, 35, 41, 567777)
>>> dt.day + (dt-datetime.datetime(dt.year, dt.month, dt.day))/datetime.timedelta(1)
8.566453330752315

Then it simply becomes a one line function so I'm closing this ticket.
History
Date User Action Args
2022-04-11 14:57:20adminsetgithub: 56981
2011-08-20 18:49:20Miguel.de.Val.Borrosetstatus: pending -> closed

messages: + msg142553
2011-08-19 22:53:10belopolskysetstatus: open -> pending

assignee: belopolsky

nosy: + belopolsky
messages: + msg142503
resolution: rejected
stage: resolved
2011-08-18 08:05:23daniel.urbansetnosy: + daniel.urban

versions: + Python 3.3, - Python 2.7
2011-08-17 16:15:02Miguel.de.Val.Borrocreate