
Pythonで
・文字列の日付をdatetime型へ変換
できます!
コード
ここでは例として
・文字列の日付「2023-12-02」をdatetime型へ変換
します。
"""文字列の日付をdatetime型へ変換する"""
from datetime import datetime
# 文字列の日付
str_date = "2023-12-02"
print(str_date)
print(type(str_date))
print("")
# 文字列の日付をdatetime型へ変換
datetime_date = datetime.strptime(str_date, "%Y-%m-%d")
print(datetime_date)
print(type(datetime_date))
実行結果
文字列の日付をdatetime型へ変換できました。

参考
上記のコードで使用した以下の詳細は、公式サイトをご確認ください。
●標準ライブラリ「datetime」モジュールの「datetime.strptime」
●組み込み関数「type」