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

Convert float days to timedelta64[ns] in pandas dataframe

I have found this where 1,5 is 1,5 days pd.to_timedelta('1,5') But it gives me 0 days 00:00:00.000000015 I needed this : 1 days 12:00:00.000000000 How to convert float days to timedelta64[ns] in a pandas column dataframe please ?
user9758331
-1
votes
1 answer

What is a proper way of doing a substraction with datetime

I have a datetime variable and I want to substract just 1 hour from it. I tried to do it with below code but I received the following error: TypeError: unsupported operand type(s) for -: 'str' and 'datetime.timedelta' from datetime import datetime,…
NorthAfrican
  • 135
  • 2
  • 10
-1
votes
3 answers

How to plus datetime in python?

I have the program that generate datetime in several format like below. 1 day, 21:21:00.561566 11:19:26.056148 Maybe it have in month or year format, and i want to know are there any way to plus these all time that i get from the program.
Kaow
  • 483
  • 2
  • 9
  • 22
-1
votes
2 answers

Truncating time to timedelta

I'm creating a date calculator and I want to just show the days, not the time. This is my code: daystoAdd = 2 date_today = date.today() result = date_today + timedelta(days=daystoAdd) print('result') And this is the…
-1
votes
2 answers

How to add month column to a date column in python?

date['Maturity_date'] = data.apply(lambda data: relativedelta(months=int(data['TRM_LNTH_MO'])) + data['POL_EFF_DT'], axis=1) Tried this also: date['Maturity_date'] = date['POL_EFF_DT'] +…
-1
votes
1 answer

can anyone explain me this(hackerrank problem) in python?

from datetime import datetime as dt fmt = '%a %d %b %Y %H:%M:%S %z' for i in range(int(input())): print(int(abs((dt.strptime(input(), fmt) - dt.strptime(input(), fmt)).total_seconds())))
yogesh sirsat
  • 13
  • 1
  • 2
-1
votes
1 answer

Median timedelta in list

With the help of this answer, I can calculate the average of a list of timedeltas in Python. timedeltas = [ ... ] # giving datetime.timedelta(0) as the start value makes sum work on tds average_timedelta = sum(timedeltas, datetime.timedelta(0)) /…
Soroosh Sorkhani
  • 66
  • 1
  • 3
  • 15
-1
votes
2 answers

How do microseconds work in a datetime.timedelta?

In the example below - I'm getting a value for seconds that do not match the microseconds. It is baffling me. Can anyone shed a light? >>> a datetime.datetime(2019, 9, 13, 21, 47, 46, 837435, tzinfo=) >>> b datetime.datetime(2019, 9, 13, 21,…
David
  • 47
  • 9
-1
votes
1 answer

Various times that are in 24 hours but they become negative time when it jumps to the next day

I am using python to calculate the time difference between start and last times. Each event has a start time and end time. I have found the difference between the columns labelled 'Interval' but they have negative values when the beginning and end…
Tina
  • 49
  • 7
-1
votes
2 answers

How to add hours to pandas datetime skipping non-business hours

I would like to create a running dataframe of trading data for the next four hours from the current time while skipping non-trading hours (5-6pm weekdays, Saturday-6pm Sunday). For example, at 4pm on Friday, I'd like a dataframe that runs from 4pm…
-1
votes
1 answer

How do I compare the timedelta between 2 columns of a CSV file?

I have 2 rows of data that look like the following (rows 8 and 9) .... 2018-01-03T10:14:32.000Z 2018-01-03T09:40:35.000Z 2018-01-03T10:17:13.000Z 2018-01-03T10:00:39.000Z 2018-01-03T10:16:53.000Z 2018-01-03T09:54:24.000Z …
-1
votes
1 answer

how to convert pandas data from to json with timdeltaindex?

Suppose I have the following example: import pandas as pd In [11]: df = pd.DataFrame(data=[0.0], index=pd.TimedeltaIndex([250], unit='d')) In [12]: df.to_json(orient='split', date_format='iso') Out[12]:…
math
  • 1,868
  • 4
  • 26
  • 60
-1
votes
1 answer

How do you convert a pandas column to time with milisecond?

I have a pandas dataframe column that pandas currently thinks is an object. It's written as "58:42.5" which is the minutes then seconds and fractions of a second. I want to convert that to a time type so that I can subtract the two time columns I…
kaecvtionr
  • 155
  • 1
  • 2
  • 9
-1
votes
1 answer

Why does it make a difference if I add 1 hour to the UTC time and localize or 1 hour to the local time?

Example Code from datetime import datetime, timezone, timedelta import pytz t11 = datetime(1918, 4, 15, 0, 0, tzinfo=timezone.utc).astimezone(pytz.timezone('Europe/Berlin')) t12 = t11 + timedelta(hours=1) t2 = datetime(1918, 4, 15, 1, 0,…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
-1
votes
1 answer

Adding time deltas to a running total in Pandas

So I have two columns of data in my dataframe. TimeDeltasDiffs and ActualTime. First row of the dataframe has a start time in the ActualTime column. I want to populate the ActualTime column incrementally based on a time delta value in the…
Auburnate
  • 437
  • 1
  • 4
  • 11