timedelta

Python's timedelta: can't I just get in whatever time unit I want the value of the entire difference?

I am trying to have some clever dates since a post has been made on my site ("seconds since, hours since, weeks since, etc..") and I'm using datetime.timedelta difference between utcnow and utc dated stored in the database for a post. Looks like, according to the docs, I have to use the days attribute AND the seconds attribute, to get t...

Python format timedelta to string

Hi, I'm a python newbie (2 weeks) and I'm having trouble formatting a datetime.timedelta object. Here's what I'm trying to do. I have a list of objects and one of the members of the class of the object is a timedelta object that shows the duration of an event. I would like to display that duration in the format of hours:minutes. I ha...

Python: How do I get time from a datetime.timedelta object?

A mysql database table has a column whose datatype is time ( http://dev.mysql.com/doc/refman/5.0/en/time.html ). When the table data is accessed, Python returns the value of this column as a datetime.timedelta object. How do I extract the time out of this? (I didn't really understand what timedelta is for from the python manuals). E.g. ...

Python timedelta in years

I need to check if some number of years have been since some date. Currently I've got timedelta from datetime module and I don't know how to convert it to years. ...

How to distribute proportionally dates on a scale with Python

I have a very simple charting component which takes integer on the x/y axis. My problem is that I need to represent date/float on this chart. So I though I could distribute proportionally dates on a scale. In other words, let's say I have the following date : 01/01/2008, 02/01/2008 and 31/12/2008. The algorithm would return 0, 16.667, an...

Missing datetime.timedelta.to_seconds() -> float in Python?

I understand that seconds and microseconds are probably represented separately in datetime.timedelta for efficiency reasons, but I just wrote this simple function: def to_seconds_float(timedelta): """Calculate floating point representation of combined seconds/microseconds attributes in :param:`timedelta`. :raise ValueError:...

Calculating the Difference Between Two Java Date Instances

I'm using Java's java.util.date class in Scala and want to compare a date object and the current time. I know I can calculate the delta by using getTime(): (new java.util.Date()).getTime() - oldDate.getTime() However, this just leaves me with a Long representing milliseconds. Is there any simpler, nicer way to get a time delta? ...

Generating a dynamic time delta: python

Hello all. Heres my situation: import foo, bar, etc frequency = ["hours","days","weeks"] class geoProcessClass(): def __init__(self,geoTaskHandler,startDate,frequency,frequencyMultiple=1,*args): self.interval = self.__determineTimeDelta(frequency,frequencyMultiple) def __determineTimeDelta(self,frequency,frequencyMu...

Convert a timedelta to days, hours and minutes

I've got a timedelta. I want the days, hours and minutes from that - either as a tuple or a dictionary... I'm not fussed. I must have done this a dozen times in a dozen languages over the years but Python usually has a simple answer to everything so I thought I'd ask here before busting out some nauseatingly simple (yet verbose) mathema...

how to convert a timedelta object into a datetime object

What is the proper way to convert a timedelta object into a datetime object? I immediately think of something like datetime(0)+deltaObj but that's not very nice... isn't there a toDateTime() function or something of the sort? ...

Python, datetime "time gap" percentage

Hello Assume I have these datatime variables: start_time, end_time, current_time I would like to know how much time left as percentage by checking current_time and the time delta between start_time and the end_time IE: Assume the interval is a 24 hours betwen start_time and end_time yet between current_time and end_time, there are 6...

Comparing a time delta in python

I have a variable which is <type 'datetime.timedelta'> and I would like to compare it against certain values. Lets say d produces this datetime.timedelta value 0:00:01.782000 I would like to compare it like this: #if d is greater than 1 minute if d>1:00: print "elapsed time is greater than 1 minute" I have tried converting datet...

Parsing an xs:duration datatype into a Python datetime.timedelta object?

As per the title, I'm trying to parse an XML file containing an xs:duration data type. I'd like to convert that into a Python timedelta object, which I can then use in further calculations. Is there any built-in way of doing this, similar to the strptime() function? If not, what is the best way to achieve this? ...

Python time objects with more than 24 hours

I have a time out of Linux that is in hh:mm:sec, but the hh can be greater than 24 hours. So if the time is 1 day 12 hours, it would be 36:00:00. Is there a way to take this format and easily make a time object? What I would really like to do is take the the required time i.e. 36:00:00, and the time that it has been running 4:46:23, a...

Python question about time spent

Hi I would like to know that how much time a particular function has spent during the duration of the program which involves recursion, what is the best way of doing it? Thank you ...

Python 2.6.5: Divide timedelta with timedelta

Hi, I'm trying to divide one timedelta object with another to calculate a server uptime: >>> import datetime >>> installation_date=datetime.datetime(2010,8,01) >>> down_time=datetime.timedelta(seconds=1400) >>> server_life_period=datetime.datetime.now()-installation_date >>> down_time_percentage=down_time/server_life_period Traceback (...

Python: How to get the sum of timedelta?

Python: How to get the sum of timedelta? Eg. I just got a lot of timedelta object, and now I want the sum. That's it! ...