Search code examples
pythondatedatetimetimestampiso8601

Timestamp subtraction in ISO8601


I have a timestamp like this: 2021-01-03T01:59:00Z. How can I write a subtraction to get the timestamp a day earlier than the one indicated in ISO 8601 format?

Thanks!


Solution

  • You can use delta for take away 1 day

    your_timestamp = '2021-01-03T01:59:00Z'
    result = datetime.datetime.strptime(your_timestamp, "%Y-%m-%dT%H:%M:%S%z") - datetime.timedelta(days=1)