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

What is python equivalent of C#'s system.datetime.Ticks()?

I would like to get python equivalent of timestamp.Ticks(), however I need it to come from a python datetime, not a time object. This is not the equivalent of Get timer ticks in Python, which asks 'how do I get the number of ticks since…
eggbert
  • 3,105
  • 5
  • 30
  • 39
13
votes
2 answers

Python time objects with more than 24 hours

I have a time out of Linux that is in hh:mm:sec, but the hh can be greater than 24 hours. So if the time is 1 day 12 hours, it would be 36:00:00. Is there a way to take this format and easily make a time object? What I would really like to do is…
mcragun
  • 1,198
  • 3
  • 10
  • 17
12
votes
3 answers

Number of seconds since the beginning of the day UTC timezone

How do I find "number of seconds since the beginning of the day UTC timezone" in Python? I looked at the docs and didn't understand how to get this using datetime.timedelta.
daydreamer
  • 87,243
  • 191
  • 450
  • 722
12
votes
1 answer

Python timedelta behaviour on subtraction

This question originated when I came upon (another thread) about Python's datetime and timedelta objects. I followed the update by jimgardener and read the comments by eyquem ,and tried out some python code ..I am having a bad time understanding the…
Damon Julian
  • 3,829
  • 4
  • 29
  • 34
12
votes
3 answers

AttributeError: 'TimedeltaProperties' object has no attribute 'minute'

I have a dataframe that looks like this df [output]: date time 2020-02-28 00:30:45 2020-02-28 00:30:45 2020-03-09 00:21:06 2020-03-09 00:21:06 2020-03-09 00:21:06 with df.time.dtype [output]: dtype('
Le Noff
  • 345
  • 1
  • 2
  • 11
12
votes
1 answer

How to convert a timedelta to minutes?

I want to calculate the difference in minutes between two datetimes. My current code results in a timedelta of '1 day, 23:33:00'. My question is how can I convert this to minutes (or generate the timedelta in minutes)? import datetime import…
Rosco
  • 121
  • 1
  • 1
  • 4
12
votes
4 answers

Android Studio Mediaplayer how to fade in and out

I am working with the mediaplayer class in android studio. I simply want to fade out one sound and fade in the other sound instead of using setVolume(0,0) and setVolume(1,1). I have created two mediaplayers for this and it seemed like I found a…
olop01
  • 273
  • 3
  • 18
12
votes
3 answers

timedelta error with numpy.longdouble dtype

I have times with dtype numpy.longdouble and when I'm trying to use that values with timedelta function I've got errors. But when I convert it to numpy.float64 everything is fine. Could somebody explain that behaviour? import numpy as np from…
Anton Protopopov
  • 30,354
  • 12
  • 88
  • 93
12
votes
5 answers

Converting datetime to timedelta so they can be added

When subtracting two datetime objects, I understand the result is timedelta object: import datetime AcDepart = 1900-01-01 18:00:00 AcArrival = 1900-01-01 07:00:00 ActualHours = AcDepart - AcArrival I want to then subtract the sum of two other…
user4490696
11
votes
1 answer

Querying timedelta column in pandas, and filtering rows

I have a column of timedelta in pandas. It is in the format x days 00:00:00. I want to filter out and flag the rows which have a value >=30 minutes. I have no clue how to do that using pandas. I tried booleans and if statements but it didn't work.…
user1541055
  • 109
  • 1
  • 7
11
votes
3 answers

Plot datetime.timedelta

I am working on a task, where I need to calculate time spent on each day and then represent that time using a bar plot, so for this task I used python and able to get time spent on each day, and stored it in a list "time_list", now I don't…
xpress_embedo
  • 377
  • 1
  • 4
  • 18
11
votes
4 answers

Add one month to a given date (rounded day after) with Python

I'd like to add one month to a given date import datetime dt = datetime.datetime(year=2014, month=5, day=2) so I should get datetime.datetime(year=2014, month=6, day=2) but with dt = datetime.datetime(year=2015, month=1, day=31) I should…
scls
  • 16,591
  • 10
  • 44
  • 55
10
votes
4 answers

Python: Given a Date and Weekday find the date of the next occurrence of a given weekday

This is a bit difficult to explain, so I apologize if this doesn't make much sense. I have a program where I am doing some scheduling. One of the settings it has is to run a task weekly on certain days. For example, weekly on Monday, Wednesday and…
Jon
  • 3,212
  • 32
  • 35
10
votes
2 answers

using the timedelta.round() function

I've seen multiple questions asked on how to define your own function that does things similar to this, but I can't figure out how to use timedelta's built in function. Does anyone have an example of a use of timedelta.round()? I have timedelta…
j robertson
  • 141
  • 1
  • 1
  • 6
10
votes
2 answers

Subtracting n days from date in Python

I want to subtract n days from a file's timestamp, but it doesn't seem to be working. I have read this post, and I think I'm close. This is an excerpt from my code: import os, time from datetime import datetime, timedelta def processData1( pageFile…
Isak
  • 535
  • 3
  • 6
  • 17