The relativedelta type, as defined by the datetutil module, is designed to be applied to an existing datetime and can replace specific components of that datetime, or represents an interval of time.
Questions tagged [relativedelta]
50 questions
1
vote
1 answer
How to calculate variance in months between dates using relativedelta
I am trying to add a new column to my DataFrame and want it to return the difference in months between two dates which are in two other columns.
I've tried several ways so far, including:
simply subtracting the dates and then dividing by…

Matan
- 117
- 11
1
vote
1 answer
relativedelta - Add # of months based on column values
I would like to add "exact months" to a start date to a start date in order to calculate an end date and have been playing with relativedelta. I have the following:
df1['Start Date'] = ['11/1/2018', '3/15/2019', NaN, '5/15/2019', '2/28/2017', NaN,…

EChan
- 105
- 6
1
vote
1 answer
Month Range Calculation Doesn't Return Expected Result
If I set the date to following:
from datetime import datetime
from dateutil import relativedelta
class count_month_range:
'Get the month range between 2 specified date based on the timezone'
def __init__(self, start_date, end_date,…

Fandratt Muda
- 140
- 11
1
vote
2 answers
How can I convert from a datetime to a weekday of the month constant?
What I want to do is figure out what X of the month this is, and returning the relative delta constant for it (Su Mo Tu...). I have found many examples of jumping to a specific day of the month (1). For instance today is the 3rd Tuesday of December…

Veggiet
- 455
- 4
- 10
1
vote
3 answers
Cannot reconstitute end date with dateutil relativedelta
I'm using dateutil.relativedelta to compute age. I was verifying the result when it appeared that in some cases, it is incorrect. The issue occurs only when the day of the start date is 1 and the end of month is 31, but not for all those months!…

papin
- 61
- 4
1
vote
1 answer
Inconsistent behavior of python-dateutil's relativedelta
Perhaps I don't understand the intent behind relativedelta, but the inconsistency in behavior whereby smaller subintervals are collapsed into larger ones so that the smallest set of subintervals are represented seems undesirable. Specifically,…

PatternMatching
- 456
- 3
- 14
1
vote
2 answers
Why does relativedelta with positive arguments return a date in the past?
I have some trouble to understand the behavior of dateutil.relativedelta.
I understand that relativedelta could return past dates if I use negative arguments as specified in relativedelta doc.
However, when I provide positive parameters, I expect…

Tanzaho
- 1,362
- 12
- 20
1
vote
1 answer
Unexpected behavior from python's relativedelta
I'm getting a confusing result when using Python's timestamps and
my_timestamp
Timestamp('2015-06-01 00:00:00')
my_timestamp + relativedelta(month = +4)
Timestamp('2015-04-01 00:00:00')
Naturally I expected the output to Timestamp('2015-10-01…

sapo_cosmico
- 6,274
- 12
- 45
- 58
1
vote
1 answer
What are differences between the singular and plural argument in 'dateutil.relativedelta.relativedelta'?
Excerpt from the description of dateutil.relativedelta.relativedelta,
year, month, day, hour, minute, second, microsecond:
Absolute information (argument is singular); adding or subtracting a
relativedelta with absolute information does not perform…

SparkAndShine
- 17,001
- 22
- 90
- 134
1
vote
1 answer
Weird arithmetic with datetimes and relativedelta
Is it safe to multiply relativedelta objects? I'm seeing some weird and inconsistent behaviour, and can't find it documented what sorts of arithmetic are supported by this class (if any)
>>> from datetime import datetime
>>> from…

wim
- 338,267
- 99
- 616
- 750
0
votes
0 answers
Why Python relativedelta perform like this?
I use the following Python to calculate the difference between two dates.
from dateutil.relativedelta import relativedelta
from datetime import datetime
date1 = datetime(2023,3,30)
date2 = datetime(2023,4,30)
delta =…

Tony
- 1
- 1
0
votes
1 answer
Python dateutils relativedelta incorrect result when starting with 30 day month
I'm trying to create some date recurrence rules. Based on the issues with dateutil noted here and here I am trying to use relativedelta rather than rrule. However, I am encountering a silly problem that is stumping me and which is illustrated with…

deepak
- 2,045
- 2
- 21
- 36
0
votes
1 answer
How can I find the elapsed business hours between two dates using pandas' CustomBusinessHour objects?
If I want to find the number of hours between two datetime objects, I can do something like this:
from datetime import datetime
today = datetime.today()
day_after_tomorrow = datetime(2022, 9, 24)
diff = (day_after_tomorrow - today).total_seconds()…

Nickolas Peter O'Malley
- 193
- 1
- 8
0
votes
1 answer
Creating a generic code and avoiding redundancies while calling relativedelta with different arguments
Is there any way that I can summarise the following code? The codes after each if-else condition are very similar. The only difference is the argument that is passed to relativedelta.
def change_datetime_objects(dt_objs=[], resolution="year",…

amiref
- 3,181
- 7
- 38
- 62
0
votes
1 answer
how to use Python relativedelta(or other ways) calculate 'Date after Months' in this dataframe?

Domingo
- 3
- 4