How can I transfer python datetime to discord DateTimeCord?

Question:

hmm… how can I turn a python DateTime obj to discord DateTimeCord (<t: ? :R>) ?

(I can transfer that using this by myself but I want to do this thing with a bot)

I had tried .toordinal() but that is not correct…

Asked By: seven eighty

||

Answers:

The number in the middle is the epoch timestamp of your Datetime instance.

py_dt = datetime.now()  # Whatever your current datetime is
epoch = round(py_dt.timestamp())  # Timestamp returns a float so round it
disc_dt = f"<t:{epoch}:R>"

You could’ve also gotten that from the Discord docs though (last two lines).

Answered By: stijndcl
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.