Date_time manipulation

Hi,

how is it possible to add a specific amount of time to a date_time object ?
E.g. I have the date_time NOW:
NOW = indico.util.date_time.utc_now
And now I want to add or subtract a specific amount of time, like:
IN_ONE_MONTH = NOW + 302460*60
But + is not a supported operand type for date_time objects, so how is that done ?

Cheers,

Phil

Hi, what are you trying to do?

utc_now() returns a normal python datetime object, so adding a timedelta to that works just fine:

>>> from indico.util.date_time import now_utc
>>> from datetime import timedelta
>>> now = now_utc()
>>> now += timedelta(weeks=4)
>>> now
datetime.datetime(2019, 4, 26, 13, 13, 24, 813399, tzinfo=<UTC>)

I am copying an old event and want to set the start date_time property of the new event adequately. So something similar to
newEvent.start_dt = utc_now() + ( oldEvent.start_dt - oldEvent.created_dt )

Using created_dt there seems wrong, but besides that it should work. Please post the exact error you get if it fails. Also print oldEvent, newEvent to see what objects you actually have there.

Sorry,

It worked exactly like I have written it down. I was only confused with another error. Thank you for your time. I managed it.

Best regards,

Philipp