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

calculate the difference between two datetime.date() dates in years and months

I want to calculate the difference between two datetime.date() dates in years and months. For example; d1 = date(2001,5,1) d2 = date(2012,1,1) d3 = date(2001,1,1) d4 = date(2012,5,1) diff1 = d2 - d1 diff2 = d4 - d3 Desired…
Tom Fin
  • 123
  • 1
  • 1
  • 8
9
votes
2 answers

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…
cdleary
  • 69,512
  • 53
  • 163
  • 191
8
votes
1 answer

How to use timedelta with pandas df.query()?

I would like to be able to pass in text from a user or file to filter pandas, which seems like query is the best way to handle it. However, I have a datetime index and can't seem to figure out a way to use timedeltas. I know I can filter dates with…
bltpyro
  • 320
  • 3
  • 13
8
votes
7 answers

timedelta to string type in pandas dataframe

I have a dataframe df and its first column is timedelta64 df.info(): RangeIndex: 686 entries, 0 to 685 Data columns (total 6 columns): 0 686 non-null timedelta64[ns] 1 686 non-null object 2 686…
Chenrui Su
  • 145
  • 1
  • 1
  • 9
8
votes
1 answer

Matplotlib timedelta64 index as x-axis

I want to plot a dataframe, which has a timedelta64 index with the index on the x-axis. The index looks like this: In [75]: test.index Out[75]: TimedeltaIndex([ '00:00:00', '00:00:00.020000', '00:00:00.040000', …
Frank
  • 149
  • 2
  • 8
8
votes
2 answers

Python - Checking if file is created today

I am trying to see if a certain file was created today. I am using Python. Does anyone have an idea on how the python code for this should be? I did some research, and people suggested timedelta. However, I was confused on how to use this check…
sye
  • 201
  • 3
  • 4
  • 10
8
votes
2 answers

Python datetime minus 1 day using timedelta

I would like the first datetime in the hyperlink to be 1 day before the second which is today's date. I read a little bit about the timedelta but I did not see how it applied within a hyperlink.…
Michael T Johnson
  • 679
  • 2
  • 13
  • 26
8
votes
2 answers

Python/Pandas Binning Data Timedelta

I have a DataFrame with two columns userID duration 0 DSm7ysk 03:08:49 1 no51CdJ 00:35:50 2 ... with 'duration' having type timedelta. I have tried using bins = [dt.timedelta(minutes = 0), dt.timedelta(minutes = …
cmf05
  • 401
  • 6
  • 15
8
votes
2 answers

formatting timedelta64 when using pandas.to_excel

I am writing to an excel file using an ExcelWriter: writer = pd.ExcelWriter(fn,datetime_format=' d hh:mm:ss') df.to_excel(writer,sheet_name='FOO') The writing operation is successful and opening the corresponding excel file I see datetimes nicely…
00__00__00
  • 4,834
  • 9
  • 41
  • 89
8
votes
2 answers

Surprising behaviour of Python date and timedelta subtraction

I am trying to do some Python date and timedelta maths and stumbled upon this. >>> import datetime >>> dt = datetime.date(2000, 4, 20) >>> td = datetime.timedelta(days=1) >>> dt - td datetime.date(2000, 4, 19) >>> -(td) + dt datetime.date(2000, 4,…
gweis
  • 116
  • 7
8
votes
2 answers

Python question about time spent

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
daydreamer
  • 87,243
  • 191
  • 450
  • 722
8
votes
1 answer

Strange behaviour when subclassing datetime.timedelta

for convenience I want to create subclasses of datetime.timedelta. The idea is to define a class as such: class Hours(datetime.timedelta): def __init__(self, hours): super(Hours, self).__init__(hours=hours) so I can quickly create…
jan
  • 1,408
  • 13
  • 19
8
votes
2 answers

sum of datetime.datetime object gave an error TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'datetime.datetime'

I'm trying to sum a list of datetime.datetime object using : from datetime import datetime, timedelta d= [datetime.datetime(2013, 5, 1, 9, 31, 24), datetime.datetime(2013, 6, 11, 17, 22, 18), datetime.datetime(2013, 4, 3, 16, 6, 59)] sum_d = sum(d,…
mongotop
  • 7,114
  • 14
  • 51
  • 76
7
votes
1 answer

Bug on astype pandas?

I am working with timedeltas and it seems this code copy_for_U.Time.astype('timedelta64[m]',copy=False); does not change the dataframe - as it should, if I understood correctly from the doc, where it says: Signature: full_df.Time.astype(dtype,…
jjrr
  • 1,038
  • 2
  • 13
  • 26
7
votes
1 answer

Pandas - combine row dates with column times

I have a dataframe: Date 0:15 0:30 0:45 ... 23:15 23:30 23:45 24:00 2004-05-01 3.74618 3.58507 3.30998 ... 2.97236 2.92008 2.80101 2.6067 2004-05-02 3.09098 3.84625 3.54672 ... 2.83725 2.93876 2.82762 …
alexbk66
  • 362
  • 1
  • 3
  • 12