0
0

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 3 years have passed since last update.

【Python】 指定した期間の日時リスト作成

Posted at

#やりたいこと
2020年10月29日 05:00から2020年11月1日 00:00の期間で6時間間隔のリストを作成したい

#pythonコード

from datetime import datetime, timedelta

def perdate(start, end, delta):
    current = start
    while current < end:
     yield current
     current += delta

for result in perdate(datetime(2020, 10, 29, 5,0,0), datetime(2020, 11, 1, 0,0,0), timedelta(hours=6)):
    print (result)

#実行結果

2020-10-29 05:00:00
2020-10-29 11:00:00
2020-10-29 17:00:00
2020-10-29 23:00:00
2020-10-30 05:00:00
2020-10-30 11:00:00
2020-10-30 17:00:00
2020-10-30 23:00:00
2020-10-31 05:00:00
2020-10-31 11:00:00
2020-10-31 17:00:00
2020-10-31 23:00:00

#参考記事

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?