Home | Legal Tech | Projects | Writings

Notice

Add days to a given date.

import arrow

print("Start date DD/MM/YYYY (leave blank for today)")
current_date = input("> ")
if current_date:
    parsed_date = arrow.get(current_date, "DD/MM/YYYY")
else:
    parsed_date = arrow.utcnow()

print("Insert time to add, e.g. 5days = d5, 5 weeks = w5, 5 months = m5, 5 years = y5")
add_time = input("> ")
added_time = int(add_time[1::])
if add_time.startswith("d"):
    calc_time = parsed_date.shift(days=+added_time).format("DD/MM/YYYY")
    print(calc_time)
elif add_time.startswith("w"):
    calc_time = parsed_date.shift(weeks=+added_time).format("DD/MM/YYYY")
    print(calc_time)
elif add_time.startswith("m"):
    calc_time = parsed_date.shift(months=+added_time).format("DD/MM/YYYY")
    print(calc_time)
elif add_time.startswith("y"):
    calc_time = parsed_date.shift(years=+added_time).format("DD/MM/YYYY")
    print(calc_time)
else:
    print("Not understood - precede number to add with unit e.g. 2 years = y2")