gd1
gd1

Reputation: 653

timedelta not working with isoformat time python

I am working with UTC time format as: 2019-04-30T18:34:34.297846 I have to calculate the timestamp with timedelta of 30 minutes: I have solved as:

from datetime import datetime, timedelta

delta = datetime.utcnow() - timedelta(minutes=29)
final = str(delta)[:10]+'T'+str(delta)[11:]
print(final)

I am wondering if it can be solved as:

delta = datetime.utcnow().isoformat() - timedelta(minutes=29)

But its not working. Looking if there is any alternatives.

Upvotes: 1

Views: 4630

Answers (1)

David Robles
David Robles

Reputation: 9607

from datetime import datetime, timedelta

delta = datetime.utcnow() - timedelta(minutes=30)
print(delta.isoformat())

# 2019-04-30T18:53:50.676939

Upvotes: 6

Related Questions