Date Assistant
For more details take a look at the docs
Installation
date-assistant is published on PyPI and can be installed from there:
pip install date-assistant
Usage
💡 Please consider that the default date format is '%Y-%m-%d'. Anyways, you can indicate the format of your date if you need to.
Functions approach
Get the difference of days, months or years between 2 dates
from date_assistant import (
get_days_diff_between,
get_months_diff_between,
get_years_diff_between,
)
from date_assistant.formats import DD_MM_YYYY, YYYY_MM
get_days_diff_between('2021-01-01', '2021-01-11')
get_days_diff_between('2021-01-01', '21-01-2021', date2_format=DD_MM_YYYY)
get_months_diff_between('2021-01-01', '2022-01-11')
get_months_diff_between('2021-01-05', '2021-02-01')
get_months_diff_between('2021-01', '2021-02-21', date1_format=YYYY_MM)
get_years_diff_between('2021-01-01', '2022-01-11')
get_years_diff_between('2021-01-05', '2022-01-01')
get_years_diff_between('2021-01', '2023-01-01', date1_format=YYYY_MM)
💡 See how months and years are only counted if a full year or month has passed.
Get the amount of years or months started between 2 dates
from date_assistant import (
get_months_started_between,
get_years_started_between,
)
from date_assistant.formats import YYYY_MM
get_months_started_between('2021-01-05', '2021-02-01')
get_months_started_between('2021-01-01', '2022-01-11')
get_months_started_between('2021-01', '2021-02-21', date1_format=YYYY_MM)
get_years_started_between('2021-01-01', '2020-12-31')
get_years_started_between('2021-01-05', '2022-01-01')
get_years_started_between('2021-01', '2023-01-01', date1_format=YYYY_MM)
💡 In contrast with the previous block example, here you don't need a full year or month between dates to count. If a new year or month started, it count.
Classes approach
Get the difference of days, months or years between 2 dates
from date_assistant import DateAssistant
my_birthday_2021 = DateAssistant('2021-07-13')
date_assistant_birthday = '2021-08-18'
my_birthday_2021.days_diff_with(date_assistant_birthday)
my_birthday_2021.months_diff_with(date_assistant_birthday)
my_birthday_2021.years_diff_with(date_assistant_birthday)
Get the amount of years or months started since or until some date
from date_assistant import DateAssistant
last_day_of_2021 = DateAssistant('2021-12-31')
first_day_of_2022 = '2022-01-01'
first_day_of_2023 = '2023-01-01'
date_assistant_birthday = '2021-08-18'
last_day_of_2021.years_started_until(first_day_of_2022)
last_day_of_2021.years_started_until(first_day_of_2023)
last_day_of_2021.months_started_until(first_day_of_2022)
last_day_of_2021.months_started_since(date_assistant_birthday)