8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python で日付の計算

Posted at

昨日の日時を取りたいと思ったら、1日分の timedelta を作って、date オブジェクトをそのまま引いてあげればいい。

>>> import datetime
>>> from datetime import timedelta
>>> t = timedelta(days = 1)
>>> d = datetime.date.today()
>>> d
datetime.date(2013, 3, 27)
>>> d - t
datetime.date(2013, 3, 26)

8.1. datetime — 基本的な日付型および時間型

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?