do not use datetime.today()

このページは日本語には対応しておりません。随時翻訳に取り組んでいます。翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください。

Metadata

ID: python-best-practices/no-datetime-today

Language: Python

Severity: Notice

Category: Best Practices

Description

Avoid using datetime.today() and use instead datetime.now(). The two calls are equivalent (as mentioned in the official documentation) and the use of now() is more explicit than today().

Using today() makes you think it only returns the year/month/day but it returns a full timestamp. For this reason, prefer using now().

Non-Compliant Code Examples

from datetime import datetime
print("foo")
bla = datetime.today()  # use datetime.now() instead

Compliant Code Examples

from datetime import datetime
print("foo")
bla = datetime.now()
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: may/unit-testing