'Python arrow add hour/minutes/etc vs replace [closed]

I wanted to use arrow vs datetime in Python, and I want to convert the following example to arrow:

end_date = start_date + timedelta(days=5)

The only thing I see in the arrow docs is:

start_date.replace(weeks=+3)

But I want to assign end_date with 5 days more than the start_date - not changing the existing start_date

I don't want to write i.e:

end_date = start_date
end_date.replace(days=+5)

I want to do it in a one-liner ... any idea ?



Solution 1:[1]

start_date.replace doesn't alter start_date, it returns a new object. So you can just assign that to a new name:

end_date = start_date.replace(days=+5)

Reading the docs is useful.

Solution 2:[2]

Ok, With arrow i assumed the todays date like

import arrow
start_date = arrow.utcnow()

Now I want to end_date is +5 days more to start_date, while start_date is unchanged.

end_date = start_date.replace(days=+5)

Is not this solved your problem?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tzaman
Solution 2 Hemel