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
93
votes
4 answers

Comparing a time delta in python

I have a variable which is and I would like to compare it against certain values. Lets say d produces this datetime.timedelta value 0:00:01.782000 I would like to compare it like this: #if d is greater than 1 minute if…
Alpesh Patel
  • 931
  • 1
  • 6
  • 3
81
votes
5 answers

How to find the date n days ago in Python?

I would like to write a script where I give Python a number of days (let's call it d) and it gives me the date we were d days ago. I am struggling with the module datetime: import datetime tod = datetime.datetime.now() d = timedelta(days = 50) a…
Dirty_Fox
  • 1,611
  • 4
  • 20
  • 24
78
votes
6 answers

Convert timedelta to floating-point

I got a timedelta object from the subtraction of two datetimes. I need this value as floating point for further calculations. All that I've found enables the calculation with floating-points, but the result is still a timedelta object. time_d =…
fidelitas
  • 1,113
  • 2
  • 12
  • 14
65
votes
7 answers

How do I remove the microseconds from a timedelta object?

I do a calculation of average time, and I would like to display the resulted average without microseconds. avg = sum(timedeltas, datetime.timedelta(0)) / len(timedeltas)
Hobbestigrou
  • 1,777
  • 1
  • 13
  • 16
64
votes
7 answers

How to add delta to python datetime.time?

From: http://docs.python.org/py3k/library/datetime.html#timedelta-objects A timedelta object represents a duration, the difference between two dates or times. So why i get error with this: >>> from datetime import datetime, timedelta, time >>>…
xliiv
  • 5,399
  • 5
  • 29
  • 35
59
votes
4 answers

How do you convert a datetime/timestamp from one timezone to another timezone?

Specifically, given the timezone of my server (system time perspective) and a timezone input, how do I calculate the system time as if it were in that new timezone (regardless of daylight savings, etc)? import datetime current_time =…
kfan
  • 1,641
  • 1
  • 13
  • 16
55
votes
1 answer

Adding seconds to a in PostgreSQL

I have a table of items with the following columns: start_time column (timestamp without time zone) expiration_time_seconds column (integer) For example, some values are: SELECT start_time, expiration_time_seconds FROM whatever ORDER…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
52
votes
3 answers

Python timedelta issue with negative values

Hi I need some help to understand why this is happening. I have a method to track 'time remaining' in an event program: def get_program_time_budget(self): return self.estimated_duration-self.get_program_duration() All fine when the…
Drew Nichols
  • 735
  • 1
  • 6
  • 13
50
votes
6 answers

Is there an easy way to convert ISO 8601 duration to timedelta?

How can I convert an ISO 8601 duration string to datetime.timedelta? I tried just instantiating timedelta with the duration string and a format string, but I get an exception: >>> from datetime import timedelta >>> timedelta("PT1H5M26S",…
Alkindus
  • 2,064
  • 2
  • 16
  • 16
47
votes
5 answers

How can I make a python numpy arange of datetime

I have some input data, with timestamps in the input file in the form of hours from the date time specified in the filename. This is a bit useless, so I need to convert it to python datetime.datetime objects, and then put it in a numpy array. I…
Melanie
  • 1,349
  • 2
  • 17
  • 27
44
votes
4 answers

Python: Difference of 2 datetimes in months

Possible Duplicate: Best way to find the months between two dates (in python) I would like to know how I can have the exact number of months for this difference: date1 = datetime.strptime(str('2011-08-15 12:00:00'), '%Y-%m-%d %H:%M:%S') date2 =…
Tiago Moutinho
  • 1,372
  • 1
  • 13
  • 18
43
votes
4 answers

Converting string 'yyyy-mm-dd' into datetime

I have a raw input from the user such as "2015-01-30"...for the query I am using, the date has to be inputed as a string as such "yyyy-mm-dd". I would like to increment the date by 1 month at end of my loop s.t "2015-01-30" becomes "2015-02-27"…
Udaya Tenneti
  • 433
  • 1
  • 4
  • 7
42
votes
5 answers

How to convert a timedelta object into a datetime object

What is the proper way to convert a timedelta object into a datetime object? I immediately think of something like datetime(0)+deltaObj, but that's not very nice... Isn't there a toDateTime() function or something of the sort?
olamundo
  • 23,991
  • 34
  • 108
  • 149
35
votes
2 answers

Pandas: add timedelta column to datetime column (vectorized)

I have a pandas dataframe with two columns, a date column and an int column, and I'd simply like to add the int column (in days) to the date column. I found a solution using df.apply(), but that was too slow on my full dataset. I don't see a ton of…
flyingmeatball
  • 7,457
  • 7
  • 44
  • 62
32
votes
6 answers

How to get the sum of timedelta in Python?

Python: How to get the sum of timedelta? Eg. I just got a lot of timedelta object, and now I want the sum. That's it!
user469652
  • 48,855
  • 59
  • 128
  • 165
1
2
3
90 91