0

Using python, how does one convert a date/time retrieved from AWS to an elapsed time from present? Depending on the actual interval, I would like to display it as years ago, days ago, hours ago, or minutes ago. This "function" will be used in several scripts used to produce monthly audit data.

|-------------------------|---------------------|-------------------------|
|Group Name               |Group Id             |Create Date              |
|=========================================================================|
|AWS-Consultants          |AGPAYPADVGQQQBEUBC6SN|2020-06-08 15:28:20+00:00|
|-------------------------|---------------------|-------------------------|
ajhowey
  • 41
  • 4
  • Does this answer your question? [How do I find the time difference between two datetime objects in python?](https://stackoverflow.com/questions/1345827/how-do-i-find-the-time-difference-between-two-datetime-objects-in-python) – Woodford Jul 30 '21 at 17:40

1 Answers1

0

You can compute a timedelta:

from datetime import datetime,timezone
create = datetime.strptime('2020-06-08 15:28:20+00:00','%Y-%m-%d %H:%M:%S%z')
print(datetime.now(timezone.utc) - create)

Output:

417 days, 1:55:45.579676
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251