Day 1 of 100 - Datetime and Timedelta Day 1 of 3

Datetime and Timedelta Day 1 of 3

Day 1 of 100

The first day of the 100 days of was a day that focused on looking at the datetime and timedelta modules. It helped me understand ways to retrieve, store, and compare dates and times. I was able to write the following snippet to get a start on calculating end of life date and compare time until end of life for the asset tracking database application that I am working on:

from datetime import date
from datetime import timedelta

# Calculating the days until EOL
asset_lifespan = timedelta(days=1825)
print(str(asset_lifespan)) # DEBUG
asset_purchase_date = date(2018, 7, 1)
asset_eol = asset_purchase_date + asset_lifespan
print(f'This asset will reach end of life on {str(asset_eol)}')
print(f'There are {asset_eol - today_date} days left until replacement')

Output:

1825 days, 0:00:00
This asset will reach end of life on 2023-06-30
There are 1099 days, 0:00:00 days left until replacement

Now, if I can only get the project complete far enough to need this functionality...