A
A
Artyom2021-04-23 18:25:27
Python
Artyom, 2021-04-23 18:25:27

How to display the date in the format “Today, Yesterday”?

Need any help on this issue. I will be grateful in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
ixon, 2018-08-16
@ixon

Depends on how it's written. It is quite possible that he responds to commands sequentially, ignoring those that are no longer relevant and one of the commands jams him.
Try to log everything, display everything that may be suspicious.

E
egoralexry, 2018-08-29
@egoralexry

I advise you to read about webhook or bot.poling Your
problem will be solved by the linebot.polling(none_stop=True)

L
Lenskii, 2021-04-23
@Milovenskii

check today's date, if it's 1 day more than the date you pass it's yesterday, if it == current date it's today. What's so difficult?

M
Maxim Nevzorov, 2021-04-23
@fixator10

Use the library humanize: https://pypi.org/project/humanize/

In [1]: import humanize

In [2]: import datetime as dt

In [3]: humanize.naturalday(dt.datetime.now() - dt.timedelta(days=1))
Out[3]: 'yesterday'

In [4]: humanize.naturalday(dt.datetime.now() + dt.timedelta(days=1))
Out[4]: 'tomorrow'

In [5]: humanize.naturalday(dt.datetime.now())
Out[5]: 'today'

In [6]: humanize.i18n.activate("ru_RU")
Out[6]: <gettext.GNUTranslations at 0x5a35478>

In [7]: humanize.naturalday(dt.datetime.now() - dt.timedelta(days=1))
Out[7]: 'вчера'

In [8]: humanize.naturalday(dt.datetime.now() + dt.timedelta(days=1))
Out[8]: 'завтра'

In [9]: humanize.naturalday(dt.datetime.now())
Out[9]: 'сегодня'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question