5/17/2020

Python - Calculate Number of Days, Weeks, or Months to Reach Specific Goals

** Calculate Number of Days, Weeks, or Months to Reach Specific Goals



==========================================

import datetime
import calendar

balance = 5000
interest_rate = 13 * .01
monthly_payment = 500

today = datetime.date.today()

days_in_current_month = calendar.monthrange(today.year, today.month)

print(days_in_current_month)

---------------------------------

(4, 31)

---------------------------------

==========================================

import datetime
import calendar

balance = 5000
interest_rate = 13 * .01
monthly_payment = 500

today = datetime.date.today()

days_in_current_month = calendar.monthrange(today.year, today.month)[1]

print(days_in_current_month)

---------------------------------

31

---------------------------------

==========================================

import datetime
import calendar

balance = 5000
interest_rate = 13 * .01
monthly_payment = 500

today = datetime.date.today()

days_in_current_month = calendar.monthrange(today.year, today.month)[1]
days_till_end_month = days_in_current_month - today.day

print(days_till_end_month)

---------------------------------

14

---------------------------------

==========================================

import datetime
import calendar

balance = 5000
interest_rate = 13 * .01
monthly_payment = 500

today = datetime.date.today()

days_in_current_month = calendar.monthrange(today.year, today.month)[1]
days_till_end_month = days_in_current_month - today.day

start_date = today + datetime.timedelta(days = days_till_end_month + 1)

print(start_date)

---------------------------------

2020-06-01

---------------------------------

==========================================

import datetime
import calendar

balance = 5000
interest_rate = 13 * .01
monthly_payment = 500

today = datetime.date.today()
days_in_current_month = calendar.monthrange(today.year, today.month)[1]
days_till_end_month = days_in_current_month - today.day

start_date = today + datetime.timedelta(days = days_till_end_month + 1)
end_date = start_date

while balance > 0:
interest_charge = (interest_rate / 12) * balance
balance += interest_charge
balance -= monthly_payment

balance = round(balance, 2)
if balance < 0:
balance = 0

# balance = 0 if balance < 0 else round(balance, 2)

print(end_date, balance)


days_in_current_month = calendar.monthrange(end_date.year, end_date.month)[1]
end_date = end_date + datetime.timedelta(days = days_in_current_month)

---------------------------------

2020-06-01 4554.17
2020-07-01 4103.51
2020-08-01 3647.96
2020-09-01 3187.48
2020-10-01 2722.01
2020-11-01 2251.5
2020-12-01 1775.89
2021-01-01 1295.13
2021-02-01 809.16
2021-03-01 317.93
2021-04-01 0

---------------------------------

==========================================

import datetime
import calendar

balance = 10000
interest_rate = 13 * .01
monthly_payment = 500

today = datetime.date.today()
days_in_current_month = calendar.monthrange(today.year, today.month)[1]
days_till_end_month = days_in_current_month - today.day

start_date = today + datetime.timedelta(days = days_till_end_month + 1)
end_date = start_date

while balance > 0:
interest_charge = (interest_rate / 12) * balance
balance += interest_charge
balance -= monthly_payment

balance = round(balance, 2)
if balance < 0:
balance = 0

# balance = 0 if balance < 0 else round(balance, 2)

print(end_date, balance)


days_in_current_month = calendar.monthrange(end_date.year, end_date.month)[1]
end_date = end_date + datetime.timedelta(days = days_in_current_month)


---------------------------------

2020-06-01 9608.33
2020-07-01 9212.42
2020-08-01 8812.22
2020-09-01 8407.69
2020-10-01 7998.77
2020-11-01 7585.42
2020-12-01 7167.6
2021-01-01 6745.25
2021-02-01 6318.32
2021-03-01 5886.77
2021-04-01 5450.54
2021-05-01 5009.59
2021-06-01 4563.86
2021-07-01 4113.3
2021-08-01 3657.86
2021-09-01 3197.49
2021-10-01 2732.13
2021-11-01 2261.73
2021-12-01 1786.23
2022-01-01 1305.58
2022-02-01 819.72
2022-03-01 328.6
2022-04-01 0

---------------------------------

==========================================

import datetime
import calendar

balance = 10000
interest_rate = 13 * .01
monthly_payment = 110

today = datetime.date.today()
days_in_current_month = calendar.monthrange(today.year, today.month)[1]
days_till_end_month = days_in_current_month - today.day

start_date = today + datetime.timedelta(days = days_till_end_month + 1)
end_date = start_date

while balance > 0:
interest_charge = (interest_rate / 12) * balance
balance += interest_charge
balance -= monthly_payment

balance = round(balance, 2)
if balance < 0:
balance = 0

# balance = 0 if balance < 0 else round(balance, 2)

print(end_date, balance)


days_in_current_month = calendar.monthrange(end_date.year, end_date.month)[1]
end_date = end_date + datetime.timedelta(days = days_in_current_month)

---------------------------------

2020-06-01 9998.33
2020-07-01 9996.65
2020-08-01 9994.95
2020-09-01 9993.23
2020-10-01 9991.49
2020-11-01 9989.73
2020-12-01 9987.95
2021-01-01 9986.15
2021-02-01 9984.33
2021-03-01 9982.49
2021-04-01 9980.63
2021-05-01 9978.75
2021-06-01 9976.85
2021-07-01 9974.93
2021-08-01 9972.99
2021-09-01 9971.03
2021-10-01 9969.05
2021-11-01 9967.05
2021-12-01 9965.03
2022-01-01 9962.98
2022-02-01 9960.91
2022-03-01 9958.82
2022-04-01 9956.71
2022-05-01 9954.57
2022-06-01 9952.41
2022-07-01 9950.23
2022-08-01 9948.02
2022-09-01 9945.79
2022-10-01 9943.54
2022-11-01 9941.26
2022-12-01 9938.96
2023-01-01 9936.63
2023-02-01 9934.28
2023-03-01 9931.9
2023-04-01 9929.5
2023-05-01 9927.07
2023-06-01 9924.61
2023-07-01 9922.13
2023-08-01 9919.62
2023-09-01 9917.08
2023-10-01 9914.52
2023-11-01 9911.93
2023-12-01 9909.31
2024-01-01 9906.66
2024-02-01 9903.98
2024-03-01 9901.27
2024-04-01 9898.53
2024-05-01 9895.76
2024-06-01 9892.96
2024-07-01 9890.13
2024-08-01 9887.27
2024-09-01 9884.38
2024-10-01 9881.46
2024-11-01 9878.51
2024-12-01 9875.53
2025-01-01 9872.51
2025-02-01 9869.46
2025-03-01 9866.38
2025-04-01 9863.27
2025-05-01 9860.12
2025-06-01 9856.94
2025-07-01 9853.72
2025-08-01 9850.47
2025-09-01 9847.18
2025-10-01 9843.86
2025-11-01 9840.5
2025-12-01 9837.11
2026-01-01 9833.68
2026-02-01 9830.21
2026-03-01 9826.7
2026-04-01 9823.16
2026-05-01 9819.58
2026-06-01 9815.96
2026-07-01 9812.3
2026-08-01 9808.6
2026-09-01 9804.86
2026-10-01 9801.08
2026-11-01 9797.26
2026-12-01 9793.4
2027-01-01 9789.5
2027-02-01 9785.55
2027-03-01 9781.56
2027-04-01 9777.53
2027-05-01 9773.45
2027-06-01 9769.33
2027-07-01 9765.16
2027-08-01 9760.95
2027-09-01 9756.69
2027-10-01 9752.39
2027-11-01 9748.04
2027-12-01 9743.64
2028-01-01 9739.2
2028-02-01 9734.71
2028-03-01 9730.17
2028-04-01 9725.58
2028-05-01 9720.94
2028-06-01 9716.25
2028-07-01 9711.51
2028-08-01 9706.72
2028-09-01 9701.88
2028-10-01 9696.98
2028-11-01 9692.03
2028-12-01 9687.03
2029-01-01 9681.97
2029-02-01 9676.86
2029-03-01 9671.69
2029-04-01 9666.47
2029-05-01 9661.19
2029-06-01 9655.85
2029-07-01 9650.46
2029-08-01 9645.01
2029-09-01 9639.5
2029-10-01 9633.93
2029-11-01 9628.3
2029-12-01 9622.61
2030-01-01 9616.85
2030-02-01 9611.03
2030-03-01 9605.15
2030-04-01 9599.21
2030-05-01 9593.2
2030-06-01 9587.13
2030-07-01 9580.99
2030-08-01 9574.78
2030-09-01 9568.51
2030-10-01 9562.17
2030-11-01 9555.76
2030-12-01 9549.28
2031-01-01 9542.73
2031-02-01 9536.11
2031-03-01 9529.42
2031-04-01 9522.66
2031-05-01 9515.82
2031-06-01 9508.91
2031-07-01 9501.92
2031-08-01 9494.86
2031-09-01 9487.72
2031-10-01 9480.5
2031-11-01 9473.21
2031-12-01 9465.84
2032-01-01 9458.39
2032-02-01 9450.86
2032-03-01 9443.24
2032-04-01 9435.54
2032-05-01 9427.76
2032-06-01 9419.89
2032-07-01 9411.94
2032-08-01 9403.9
2032-09-01 9395.78
2032-10-01 9387.57
2032-11-01 9379.27
2032-12-01 9370.88
2033-01-01 9362.4
2033-02-01 9353.83
2033-03-01 9345.16
2033-04-01 9336.4
2033-05-01 9327.54
2033-06-01 9318.59
2033-07-01 9309.54
2033-08-01 9300.39
2033-09-01 9291.14
2033-10-01 9281.79
2033-11-01 9272.34
2033-12-01 9262.79
2034-01-01 9253.14
2034-02-01 9243.38
2034-03-01 9233.52
2034-04-01 9223.55
2034-05-01 9213.47
2034-06-01 9203.28
2034-07-01 9192.98
2034-08-01 9182.57
2034-09-01 9172.05
2034-10-01 9161.41
2034-11-01 9150.66
2034-12-01 9139.79
2035-01-01 9128.8
2035-02-01 9117.7
2035-03-01 9106.48
2035-04-01 9095.13
2035-05-01 9083.66
2035-06-01 9072.07
2035-07-01 9060.35
2035-08-01 9048.5
2035-09-01 9036.53
2035-10-01 9024.43
2035-11-01 9012.19
2035-12-01 8999.82
2036-01-01 8987.32
2036-02-01 8974.68
2036-03-01 8961.91
2036-04-01 8949.0
2036-05-01 8935.95
2036-06-01 8922.76
2036-07-01 8909.42
2036-08-01 8895.94
2036-09-01 8882.31
2036-10-01 8868.54
2036-11-01 8854.62
2036-12-01 8840.55
2037-01-01 8826.32
2037-02-01 8811.94
2037-03-01 8797.4
2037-04-01 8782.71
2037-05-01 8767.86
2037-06-01 8752.85
2037-07-01 8737.67
2037-08-01 8722.33
2037-09-01 8706.82
2037-10-01 8691.14
2037-11-01 8675.29
2037-12-01 8659.27
2038-01-01 8643.08
2038-02-01 8626.71
2038-03-01 8610.17
2038-04-01 8593.45
2038-05-01 8576.55
2038-06-01 8559.46
2038-07-01 8542.19
2038-08-01 8524.73
2038-09-01 8507.08
2038-10-01 8489.24
2038-11-01 8471.21
2038-12-01 8452.98
2039-01-01 8434.55
2039-02-01 8415.92
2039-03-01 8397.09
2039-04-01 8378.06
2039-05-01 8358.82
2039-06-01 8339.37
2039-07-01 8319.71
2039-08-01 8299.84
2039-09-01 8279.75
2039-10-01 8259.45
2039-11-01 8238.93
2039-12-01 8218.19
2040-01-01 8197.22
2040-02-01 8176.02
2040-03-01 8154.59
2040-04-01 8132.93
2040-05-01 8111.04
2040-06-01 8088.91
2040-07-01 8066.54
2040-08-01 8043.93
2040-09-01 8021.07
2040-10-01 7997.96
2040-11-01 7974.6
2040-12-01 7950.99
2041-01-01 7927.13
2041-02-01 7903.01
2041-03-01 7878.63
2041-04-01 7853.98
2041-05-01 7829.06
2041-06-01 7803.87
2041-07-01 7778.41
2041-08-01 7752.68
2041-09-01 7726.67
2041-10-01 7700.38
2041-11-01 7673.8
2041-12-01 7646.93
2042-01-01 7619.77
2042-02-01 7592.32
2042-03-01 7564.57
2042-04-01 7536.52
2042-05-01 7508.17
2042-06-01 7479.51
2042-07-01 7450.54
2042-08-01 7421.25
2042-09-01 7391.65
2042-10-01 7361.73
2042-11-01 7331.48
2042-12-01 7300.9
2043-01-01 7269.99
2043-02-01 7238.75
2043-03-01 7207.17
2043-04-01 7175.25
2043-05-01 7142.98
2043-06-01 7110.36
2043-07-01 7077.39
2043-08-01 7044.06
2043-09-01 7010.37
2043-10-01 6976.32
2043-11-01 6941.9
2043-12-01 6907.1
2044-01-01 6871.93
2044-02-01 6836.38
2044-03-01 6800.44
2044-04-01 6764.11
2044-05-01 6727.39
2044-06-01 6690.27
2044-07-01 6652.75
2044-08-01 6614.82
2044-09-01 6576.48
2044-10-01 6537.73
2044-11-01 6498.56
2044-12-01 6458.96
2045-01-01 6418.93
2045-02-01 6378.47
2045-03-01 6337.57
2045-04-01 6296.23
2045-05-01 6254.44
2045-06-01 6212.2
2045-07-01 6169.5
2045-08-01 6126.34
2045-09-01 6082.71
2045-10-01 6038.61
2045-11-01 5994.03
2045-12-01 5948.97
2046-01-01 5903.42
2046-02-01 5857.37
2046-03-01 5810.82
2046-04-01 5763.77
2046-05-01 5716.21
2046-06-01 5668.14
2046-07-01 5619.54
2046-08-01 5570.42
2046-09-01 5520.77
2046-10-01 5470.58
2046-11-01 5419.84
2046-12-01 5368.55
2047-01-01 5316.71
2047-02-01 5264.31
2047-03-01 5211.34
2047-04-01 5157.8
2047-05-01 5103.68
2047-06-01 5048.97
2047-07-01 4993.67
2047-08-01 4937.77
2047-09-01 4881.26
2047-10-01 4824.14
2047-11-01 4766.4
2047-12-01 4708.04
2048-01-01 4649.04
2048-02-01 4589.4
2048-03-01 4529.12
2048-04-01 4468.19
2048-05-01 4406.6
2048-06-01 4344.34
2048-07-01 4281.4
2048-08-01 4217.78
2048-09-01 4153.47
2048-10-01 4088.47
2048-11-01 4022.76
2048-12-01 3956.34
2049-01-01 3889.2
2049-02-01 3821.33
2049-03-01 3752.73
2049-04-01 3683.38
2049-05-01 3613.28
2049-06-01 3542.42
2049-07-01 3470.8
2049-08-01 3398.4
2049-09-01 3325.22
2049-10-01 3251.24
2049-11-01 3176.46
2049-12-01 3100.87
2050-01-01 3024.46
2050-02-01 2947.22
2050-03-01 2869.15
2050-04-01 2790.23
2050-05-01 2710.46
2050-06-01 2629.82
2050-07-01 2548.31
2050-08-01 2465.92
2050-09-01 2382.63
2050-10-01 2298.44
2050-11-01 2213.34
2050-12-01 2127.32
2051-01-01 2040.37
2051-02-01 1952.47
2051-03-01 1863.62
2051-04-01 1773.81
2051-05-01 1683.03
2051-06-01 1591.26
2051-07-01 1498.5
2051-08-01 1404.73
2051-09-01 1309.95
2051-10-01 1214.14
2051-11-01 1117.29
2051-12-01 1019.39
2052-01-01 920.43
2052-02-01 820.4
2052-03-01 719.29
2052-04-01 617.08
2052-05-01 513.77
2052-06-01 409.34
2052-07-01 303.77
2052-08-01 197.06
2052-09-01 89.19
2052-10-01 0

---------------------------------

==========================================


import datetime

current_weight = 220
goal_weight = 180
avg_lbs_week = 1.5

start_date = datetime.date.today()
end_date = start_date

while current_weight > goal_weight:
end_date += datetime.timedelta(days = 7)
current_weight -= avg_lbs_week

print(f'Reached goal in {(end_date - start_date).days // 7} weeks')

---------------------------------

Reached goal in 27 weeks

---------------------------------

==========================================

import datetime

current_weight = 220
goal_weight = 180
avg_lbs_week = 1.5

start_date = datetime.date.today()
end_date = start_date

while current_weight > goal_weight:
end_date += datetime.timedelta(days = 7)
current_weight -= avg_lbs_week

print(end_date)
print(f'Reached goal in {(end_date - start_date).days // 7} weeks')


---------------------------------

2020-11-22
Reached goal in 27 weeks

---------------------------------

==========================================

import datetime

current_weight = 220
goal_weight = 180
avg_lbs_week = 2

start_date = datetime.date.today()
end_date = start_date

while current_weight > goal_weight:
end_date += datetime.timedelta(days = 7)
current_weight -= avg_lbs_week

print(end_date)
print(f'Reached goal in {(end_date - start_date).days // 7} weeks')

---------------------------------

2020-10-04
Reached goal in 20 weeks

---------------------------------

==========================================

import datetime
import math

goal_subs = 100000
current_subs = 85000
subs_to_go = goal_subs - current_subs

avg_subs_day = 200
days_to_go = math.ceil(subs_to_go / avg_subs_day)

today = datetime.date.today()

print(today + datetime.timedelta(days = days_to_go))

---------------------------------

2020-07-31

---------------------------------

==========================================

import datetime
import math

goal_subs = 150000
current_subs = 85000
subs_to_go = goal_subs - current_subs

avg_subs_day = 200
days_to_go = math.ceil(subs_to_go / avg_subs_day)

today = datetime.date.today()

print(today + datetime.timedelta(days = days_to_go))

---------------------------------

2021-04-07

---------------------------------