0
0

More than 1 year has passed since last update.

Pythonの小技3

Posted at

DateTimeの処理

from datetime import datetime

datetime_1 = '20210321'
datetime_2 = '20210301'

# 文字列からフォーマットを指定してdatetime型へ変換
convert_datetime_1 = datetime.strptime(datetime_1, '%Y%m%d')
convert_datetime_2 = datetime.strptime(datetime_2, '%Y%m%d')
dt = convert_datetime_1 - convert_datetime_2
print(dt.days) 
print(type(dt.days)) #int
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