LoginSignup
3

More than 5 years have passed since last update.

datetime型の引き算で勘違い

Posted at

pythonではdatetime型同士の引き算はdatetime.timedelta型になる

このときの変数名 pokoとして

poko.seconds
poko.days

のようにアクセスして差分がとれる

勘違いポイント

secondsは差分を返してくれると思ったが日付で繰り上げられる

どういうことかというと差分が1日と30秒あったとしたら86400 + 30で
86430を返してくれると思ったが、実際は30がえられる。

で daysが 0 -> 1に繰り上げられる

という点ではまった

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
3