日付から曜日を数値で取得: datetime.weekday(), calendar.weekday() datetime.weekday(), date.weekday() 日時(日付と時間)を表すdatetime.datetimeオブジェクトのweekday()メソッドで、曜日を表す整数値が得られる。月曜日が0で日曜日が6。 datetime.datetime.weekday() — Python 3.12.0 ドキュメント import datetime dt = datetime.datetime(2023, 1, 1) print(dt) # 2023-01-01 00:00:00 print(dt.weekday()) # 6 print(type(dt.weekday())) # <class 'int'>
![Pythonで日付から曜日・月を数値・文字列で取得 | note.nkmk.me](https://cdn-ak-scissors.b.st-hatena.com/image/square/b652e82d0051188633a4d835d786a6618683dc85/height=288;version=1;width=512/https%3A%2F%2Fi.gyazo.com%2F651fd0280abf1072631d3669837e78ba.png)