Questions tagged [timedelta]

Timedelta refers to the difference between two timestamps, which is a measure of elapsed time. It may also specifically refer to the 'timedelta' type in Python.

Timedelta refers to the difference between two timestamps, which is a measure of elapsed time. It may also specifically refer to the timedelta type in Python.

In it is represented by Time.deltaTime which holds the elapsed time between frames and allows to coordinate animations and movement of gameObjects.

It is similar to the TimeSpan structure in .NET.

Other languages may have similar features as well.

See also the and tags.

1357 questions
19
votes
2 answers

Python Pandas: TypeError: unsupported operand type(s) for +: 'datetime.time' and 'Timedelta'

I am attempting to add two series in a dataframe in pandas with the first series being a 24-hr time value (e.g. 17:30) exported from an excel file and the second series being a series of the same length in Timedelta format converted from floats with…
DoctorWhom
  • 219
  • 1
  • 2
  • 7
19
votes
1 answer

Python 2.6.5: Divide timedelta with timedelta

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) >>>…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
19
votes
2 answers

Determining "days" in python when the timedelta.days is less than one

sorry in advance if this is dense. I am trying to find the days since I last posted a tweet. The problem I am running into is when the dates are different, e.g., today and yesterday, but not enough hours have passed to be a full "day." #…
psxndc
  • 193
  • 1
  • 1
  • 5
18
votes
2 answers

Convert datetime.time into datetime.timedelta in Python 3.4

I am trying to convert two "durations", however I am currently receiving a TypeError due to one being a datetime.timedelta and one being a datetime.time: TypeError: unorderable types: datetime.time() <= datetime.timedelta() What is an efficient way…
Rob Murray
  • 1,773
  • 6
  • 20
  • 32
18
votes
2 answers

Django: Using F arguments in datetime.timedelta inside a query

Using Django model syntax, if I do this: ThatModel.objects.filter( last_datetime__lte=now + datetime.timedelta(seconds=F("interval"))) I get: TypeError: unsupported type for timedelta days component: ExpressionNode Is there a way to make this…
Synthead
  • 2,162
  • 5
  • 22
  • 25
17
votes
5 answers

Pandas measure elapsed time since a condition

I have the following dataframe: Time Work 2018-12-01 10:00:00 Off 2018-12-01 10:00:02 On 2018-12-01 10:00:05 On 2018-12-01 10:00:06 On 2018-12-01 10:00:07 On 2018-12-01 10:00:09 Off 2018-12-01 10:00:11 …
Rafael
  • 193
  • 5
17
votes
3 answers

Convert a datetime.timedelta into ISO 8601 duration in Python?

Given a datetime.timedelta, how to convert it into an ISO 8601 duration string? For example, given datetime.timedelta(0, 18, 179651), how do I get 'PT18.179651S'? For the reverse, see Is there an easy way to convert ISO 8601 duration to timedelta?.
Drake Guan
  • 14,514
  • 15
  • 67
  • 94
16
votes
4 answers

need the average from a list of timedelta objects

I have created a list of timedelta objects and i need to get the average of this list. when i try to do return (sum(delta_list)/(len(delta_list)-1)) i get TypeError: unsupported operand type(s) for +: 'int' and 'datetime.timedelta' I am new at…
Cory
  • 513
  • 5
  • 14
16
votes
1 answer

Python: Adding hours to pandas timestamp

I read a csv file into pandas dataframe df and I get the following: df.columns Index([u'TDate', u'Hour', u'SPP'], dtype='object') >>> type(df['TDate'][0]) type(df['Hour'][0]) >>>…
Zanam
  • 4,607
  • 13
  • 67
  • 143
14
votes
4 answers

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,…
Bjorn
  • 69,215
  • 39
  • 136
  • 164
14
votes
4 answers

Add 15 minutes to current timestamp using timedelta

The title says it all. I am writing a script to make scheduled GET requests to an API. I want to print when the next API call will be made, which would be 15 minutes from the previous call. I'm very close, but have been running into the following…
philiporlando
  • 941
  • 4
  • 19
  • 31
14
votes
1 answer

Pandas adding Time column to Date index

I have a dataframe, Date index type is Timestamp, Time column is datetime.Time: Time Value Date 2004-05-01 0:15 3.58507 2004-05-02 0:30 3.84625 ... How do I convert it to: Value Date 2004-05-01…
alexbk66
  • 362
  • 1
  • 3
  • 12
14
votes
3 answers

How to add weekly timedeltas with regards to daylight saving timezones

I want to add or subtract weeks (or days or month or years) to localized datetime objects. The problem is, that the naive approach will result in 1 hour shifts due to daylight saving timezones. 2014-03-27 12:00 is right before the switch from winter…
davidn
  • 812
  • 8
  • 13
13
votes
3 answers

How to find one month later from a date with django?

I want to find one month later from a date but I don't know how. Lets say I have this date: 08.03.2012 I want to find one month later from that date automatically like: 08.04.2012 Does anyone know how to do that?
Eren Süleymanoğlu
  • 1,204
  • 3
  • 18
  • 26
13
votes
3 answers

Python add days in epoch time

How to add days in epoch time in Python #lssec -a lastupdate -s root -f /etc/security/passwd 2>/dev/null | cut -f2 -d= 1425917335 above command giving me epoch time I want to add 90 days in that time. how do I add days in epoch time?
Satish
  • 16,544
  • 29
  • 93
  • 149