Examples of time subtraction in Python. Using the best date-time library called Pendulum. You can use add or subtract to alter time.
Source code viewer
import pendulum # Get required timezone. timezone = pendulum.timezone('Europe/Tallinn') # Get current time in the right timezone. current_time = pendulum.now(timezone) # Minus one year (-1 year) and apply format you like (https://pendulum.eustace.io/docs/#tokens). current_time.subtract(years=1).format('DD.MM.YYYY') # Minus one month (-1 month). current_time.subtract(months=1) # Minus six months (-6 months). current_time.subtract(months=6) # Minus one day (-1 day). current_time.subtract(days=1) # Minus 30 days (-30 days), to get last 30 days for an example. current_time.subtract(days=30) # Minus one week (-1 week). current_time.add(weeks=1) # Minus one hour (-1 hour). current_time.subtract(hours=1) # Minus five minutes (-5 minutes). current_time.subtract(minutes=5) # Minus ten seconds (-10 seconds). current_time.subtract(seconds=10) # Exact/precise time subscraction. current_time.subtract(years=1, months=2, days=7, hours=5, minutes=30, seconds=10)Programming Language: Python