import datetime
import telebot
from time import strftime
token = 'МОЙ ТОКЕН'
bot = telebot.TeleBot(token)
@bot.message_handler(commands=['start'])
def handle_command(message):
msg = bot.reply_to(message,
"Здравствуйте, *" + message.from_user.first_name + '* введите дату в формате: дд-мм-гггг: ',
parse_mode='Markdown')
bot.register_next_step_handler(msg, main)
def main(message):
today = datetime.date.today()
now = datetime.datetime.now()
then = datetime.datetime.strptime(message.text, "%d-%m-%Y")
print(now-then)
if __name__ == '__main__':
bot.polling(none_stop=True)
test_date = input("Ввведите дату в формате 'dd-mm-yyyy': ")
now = datetime.datetime.now()
then = datetime.datetime.strptime(test_date, "%d-%m-%Y")
delta1 = datetime.datetime(now.year, then.month, then.day)
delta2 = datetime.datetime(now.year+1, then.month, then.day)
result = ((delta1 if delta1 > now else delta2) - now).days
print(f'До вашего следущего дня рождения осталось {result} дней')
>>> from datetime import date
>>> today = date.today()
>>> today
datetime.date(2022, 12, 12)
>>> lastbirthday = date(today.year, 6, 14)
>>> today - lastbirthday
datetime.timedelta(days=181)
>>> today >= lastbirthday
True
>>> lastbirthday = date(today.year+1, 6, 14)
>>> today >= lastbirthday
False
>>> lastbirthday - today
datetime.timedelta(days=184)
>>>