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
32
votes
3 answers

From TimeDelta to float days in Pandas

I have a TimeDelta column with values that look like this: 2 days 21:54:00.000000000 I would like to have a float representing the number of days, let's say here 2+21/24 = 2.875, neglecting the minutes. Is there a simple way to do this ? I saw an…
alpagarou
  • 471
  • 2
  • 5
  • 11
31
votes
1 answer

How to calculate time difference by group using pandas?

Problem I want to calculate diff by group. And I don’t know how to sort the time column so that each group results are sorted and positive. The original data : In [37]: df Out[37]: id time 0 A 2016-11-25 16:32:17 1 A 2016-11-25…
Jack
  • 1,724
  • 4
  • 18
  • 33
31
votes
9 answers

Calculate datetime difference in years, months, etc. in a new pandas dataframe column

I have a pandas dataframe looking like this: Name start end A 2000-01-10 1970-04-29 I want to add a new column providing the difference between the start and end column in years, months, days. So the result should look like: Name …
beta
  • 5,324
  • 15
  • 57
  • 99
30
votes
3 answers

Why is Python datetime time delta not found?

I am trying to make an array of dates in mmddyyyy format. The dates will start on the current day and then go two weeks into the future. So it all depends on the starting date. When I run my code I get an error that states: Traceback (most recent…
questionier
  • 359
  • 1
  • 5
  • 15
29
votes
4 answers

Finding the mean and standard deviation of a timedelta object in pandas df

I would like to calculate the mean and standard deviation of a timedelta by bank from a dataframe with two columns shown below. When I run the code (also shown below) I get the below error: pandas.core.base.DataError: No numeric types to…
Graham Streich
  • 874
  • 3
  • 15
  • 31
28
votes
4 answers

Average timedelta in list

I want to calculate the avarage timedelta between dates in a list. Although the following works well, I'm wondering if there's a smarter way? delta = lambda last, next: (next - last).seconds + (next - last).days * 86400 total =…
shinn
  • 291
  • 1
  • 3
  • 4
27
votes
2 answers

AttributeError: 'Series' object has no attribute 'days'

I have a column 'delta' in a dataframe dtype: timedelta64[ns], calculated by subcontracting one date from another. I am trying to return the number of days as a float by using this code: from datetime import datetime from datetime import…
OllieP
  • 291
  • 1
  • 4
  • 9
26
votes
3 answers

How can I perform divison on a datetime.timedelta in python?

I'd like to be able to do the following: num_intervals = (cur_date - previous_date) / interval_length or print (datetime.now() - (datetime.now() - timedelta(days=5))) / timedelta(hours=12) # won't run, would like it to print '10' but the…
Luke
  • 18,585
  • 24
  • 87
  • 110
26
votes
4 answers

Using datetime.timedelta to add years

I am doing some time calculations in Python. Goal: Part of this is trying to : Given a date, add time interval (X years, X months, X weeks), return date ie input args: input_time (datetime.date), interval (datetime.timedelta) return:…
patrick
  • 4,455
  • 6
  • 44
  • 61
25
votes
2 answers

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…
Sam
  • 681
  • 1
  • 7
  • 12
24
votes
6 answers

Round time to nearest hour python

I was trying to round off time to the nearest hour in python in a dataframe. Suppose if a timestamp is 2017-11-18 0:16 it should come as 2017-11-18 0:00 and 2017-11-18 1:56 should round off as 2017-11-18 2:00
user123
  • 467
  • 1
  • 3
  • 10
24
votes
3 answers

Python - Date & Time Comparison using timestamps, timedelta

I've spent the past hour digging around the Python docs and many SO questions; please forgive me for being another Python newbie trapped by the mystery of time difference in Python. My goal is to determine the difference between the current time and…
daltonf
  • 430
  • 1
  • 3
  • 8
23
votes
6 answers

Displaying a timedelta object in a django template

I'm having trouble getting my django template to display a timedelta object consistently. I tried using the time filter in my template, but nothing is displayed when I do this. The timedelta object is shown as follows on the errors page if I use…
bgmaster
  • 2,313
  • 4
  • 28
  • 41
22
votes
3 answers

Something like python timedelta in golang

I want to get a datetime, counting weeks from a date, days from a week and seconds from 00:00 time. With Python I can use this: BASE_TIME = datetime.datetime(1980,1,6,0,0) tdelta = datetime.timedelta(weeks = 1722, days =…
chespinoza
  • 2,638
  • 1
  • 23
  • 46
21
votes
2 answers

Timedelta multiply with float in python

I have two dates and can calculate timedelta as usual. But I want to calculate some percent with resulting timedelta: full_time = (100/percentage) * timdelta But it seems that it can only multiplying with interegs. How can I use float instead of…
Крайст
  • 776
  • 1
  • 9
  • 22
1 2
3
90 91