timedelta

Trying to create a list of random times within specific date/time conditions

Trying to create a list of random times within specific date/time conditions Question: I am trying to modify this GitHub code for my own purposes in the title: import random from datetime import datetime, timedelta min_year=1900 max_year=datetime.now().year start = datetime(min_year, 1, 1, 00, 00, 00) years = max_year – min_year+1 end = start + timedelta(days=365 …

Total answers: 2

Convert datetime and timedelta from Python to IDL

Convert datetime and timedelta from Python to IDL Question: Please does anyone know how to convert the following python script to IDL, hours = list(Timed) start_date = datetime(year=1800, month=1, day=1, hour=0, minute=0, second=0) days =[] Months =[] Years =[] for hour in hours: date = start_date + timedelta(hours=hour) Months.append(date.month) Years.append(date.year) The script converts the data …

Total answers: 1

Calculating timedeltas across daylight saving

Calculating timedeltas across daylight saving Question: I’m facing a python timezones problem and am unsure of what is the right approach to deal with it. I have to calculate timedeltas from given start and end DateTime objects. It can happen that daylight saving time will change during the runtime of my events, so I have …

Total answers: 1

How to convert a difference in timestamp to miliseconds?

How to convert a difference in timestamp to miliseconds? Question: I have two dates in timestamp and their difference is dt 0.006951093673706055 dt is: (1669983551.287477-1669983551.280526) I want to generate several dates (in datetime) with that difference Now normally I would do date_list = [datetime.now() + datetime.timedelta(milliseconds=x) for x in range(n)] but here timedelta uses the …

Total answers: 1

pandas python how to convert time duration to milliseconds?

pandas python how to convert time duration to milliseconds? Question: I have a df ,you can have it by copy and run the following code: import pandas as pd from io import StringIO df = """ b_id duration1 duration2 user 384 28 days 21:05:16.141263 0 days 00:00:44.999706 Test """ df= pd.read_csv(StringIO(df.strip()), sep=’ss+’, engine=’python’) df My …

Total answers: 2

How to add a duration to datetime in Python polars

How to add a duration to datetime in Python polars Question: I want to add a duration in seconds to a date/time. My data looks like import polars as pl df = pl.DataFrame( { "dt": [ "2022-12-14T00:00:00", "2022-12-14T00:00:00", "2022-12-14T00:00:00", ], "seconds": [ 1.0, 2.2, 2.4, ], } ) df = df.with_column(pl.col("dt").str.strptime(pl.Datetime).cast(pl.Datetime)) Now my naive attempt …

Total answers: 2

Convert timedelta to milliseconds python

Convert timedelta to milliseconds python Question: I have the following time: time = datetime.timedelta(days=1, hours=4, minutes=5, seconds=33, milliseconds=623) Is it possible, to convert the time in milliseconds? Like this: 101133623.0 Asked By: hubi3012 || Source Answers: It’s certainly possible. 1 day + 4 hours + 5 minutes + 33 seconds + 623 milliseconds = 24 …

Total answers: 2

Python Datetime Subtration include 0 to hour section

Python Datetime Subtraction include 0 to hour section Question: I’ve 2 strings of datetime, I need to subtract those to get duration but when subtracted for hour section it only contain 1 digit eg: 1:30, 2:30 So, my question is can we get subtracted datetime or string which includes 0 at the beginning eg: 01:30, …

Total answers: 2

Python: Plotting time delta

Python: Plotting time delta Question: I have a DataFrame with a column of the time and a column in which I have stored a time lag. The data looks like this: 2020-04-18 14:00:00 0 days 03:00:00 2020-04-19 02:00:00 1 days 13:00:00 2020-04-28 14:00:00 1 days 17:00:00 2020-04-29 20:00:00 2 days 09:00:00 2020-04-30 19:00:00 2 days …

Total answers: 1

Calculate a date difference between two dates in a series of a dataframe by ID?

Calculate a date difference between two dates in a series of a dataframe by ID? Question: Sorry if my question is simple i’m starting(so thank you for your help and understanding) I am trying to get a date discrepancy by ‘identifier’ A B C D in the DF example. Using Python how can i add …

Total answers: 1