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
10
votes
1 answer

How to convert float to timedelta seconds in python?

How do you instantiate a datetime.timedelta to a number of seconds in python? For example, 43880.6543 Edit (as per clarification by OP): I have an Excel sheet, where a cell shows 43880.6543 (when the format is Generic) instead of a date. How do I…
alwbtc
  • 28,057
  • 62
  • 134
  • 188
10
votes
2 answers

Session generation from log file analysis with pandas

I'm analysing a Apache log file and I have imported it in to a pandas dataframe. '65.55.52.118 - - [30/May/2013:06:58:52 -0600] "GET /detailedAddVen.php?refId=7954&uId=2802 HTTP/1.1" 200 4514 "-" "Mozilla/5.0 (compatible; bingbot/2.0;…
Nilani Algiriyage
  • 32,876
  • 32
  • 87
  • 121
9
votes
3 answers

how to convert string to datetime.timedelta()?

how can i convert my string of date to a datetime.timedelta() in Python? I have this code : import datetime date_select = '2011-12-1' delta = datetime.timedelta(days=1) target_date = date_select + delta print target_date thanks in advance ...
gadss
  • 21,687
  • 41
  • 104
  • 154
9
votes
5 answers

Negative time difference in Pandas

I get this strange result by substracting earlier time stamp for later one: pd.to_datetime('2021-05-21 06:00:00') - pd.to_datetime('2021-05-21 06:02:00') Output: Timedelta('-1 days +23:58:00') Expected Output: Timedelta('-0 days 00:02:00') What…
Mykola Zotko
  • 15,583
  • 3
  • 71
  • 73
9
votes
4 answers

Convert string to timedelta in pandas

I have a series where the timestamp is in the format HHHHH:MM: timestamp = pd.Series(['34:23', '125:26', '15234:52'], index=index) I would like to convert it to a timedelta series. For now I manage to do that on a single…
Gilles L
  • 165
  • 1
  • 3
  • 8
9
votes
4 answers

Remove the days in the timedelta object

I have a column in a pandas dataframe that is created after subtracting two times. I now have a timedelta object like this -1 days +02:45:00. I just need to remove the -1 days and want it to be 02:45:00. Is there a way to do this?
Harikrishna
  • 1,100
  • 5
  • 13
  • 30
9
votes
2 answers

Python Timedelta64 convert days to months

I have a Pandas dataframe with 2 columns representing a start-timestamp and an end-timestamp: start end 2016-06-13 2016-07-20 The datatype of these columns is datetime64[ns]. I now want to create a new column showing the difference in…
beta
  • 5,324
  • 15
  • 57
  • 99
9
votes
2 answers

Timedelta object cannot be converted with astype()

A native Pandas Timedelta() (with version 0.20.3), can't convert to a specific frequency with astype(), although the docs say it should be possible. I'm trying to figure out what I'm missing. From the Timedelta docs: Timedelta Series,…
andrew_reece
  • 20,390
  • 3
  • 33
  • 58
9
votes
1 answer

How to calculate time between events in a pandas

Original Question I'm stuck on the following problem. I'm trying to figure out at which moments in time and for how long a vehicle is situated at the factory. I have an excel sheet in which all events are stored which are either delivery routes or…
jeff
  • 151
  • 7
9
votes
3 answers

How Do I Format a pandas timedelta object?

I am using pandas timedelta objects to keep track of split times in a sports related data set using the following sort of construction: import pandas as pd pd.to_timedelta("-0:0:1.0") This natively reports as: -1 days +23:59:59 I can get the raw…
psychemedia
  • 5,690
  • 7
  • 52
  • 84
9
votes
4 answers

How to convert timedelta to time of day in pandas?

I have a SQL table that contains data of the mySQL time type as follows: time_of_day ----------- 12:34:56 I then use pandas to read the table in: df = pd.read_sql('select * from time_of_day', engine) Looking at df.dtypes yields: time_of_day …
ryantuck
  • 6,146
  • 10
  • 57
  • 71
9
votes
3 answers

how to extract days as integers from a timedelta64[ns] object in python

I have a pandas dataframe with a column like: In [96]: data['difference'] Out[96]: 0 NaT 1 1 days 21:34:30 2 0 days 16:57:36 3 0 days 00:16:51 4 0 days 15:52:38 5 0 days 14:19:34 6 0 days 02:54:46 7 1…
Blue Moon
  • 4,421
  • 20
  • 52
  • 91
9
votes
3 answers

Infinite Timedelta in Python

How can you express an infinite timedelta in Python? Up to now we use datetime from stdlib, but we could switch, if it is only supported in a third party library. PostgreSQL does support it. And it would be handy in my case. I want to use it to…
guettli
  • 25,042
  • 81
  • 346
  • 663
9
votes
6 answers

HTML5 Canvas game loop delta time calculations

I'm new to game development. Currently I'm doing a game for js13kgames contest, so the game should be small and that's why I don't use any of modern popular frameworks. While developing my infinite game loop I found several articles and pieces of…
Kosmetika
  • 20,774
  • 37
  • 108
  • 172
9
votes
3 answers

What's the best way to store a python timedelta value in mysql?

I need to store an uptime in a mysql environment. The uptime can vary from a few hours to more than one year. I was considering using a DATETIME type for mysql. I'm working with python, and the uptime is obtained from def convertdate(lastrestart): …
asdf
  • 685
  • 7
  • 23