datetime.replaceメソッドでは、datetimeオブジェクトの内容を一部書き換えることが可能です。
datetime.replaceメソッド

説明用にdatetime形式の日時を作っておきます。

実行すると図のように、年月日は指定した数値が入り、指定していない時間以降は初期値の0が入ります。

この日付を書き換えるには、まるごと新しい日付をdatetimeオブジェクトに代入する他に、
#python
import datetime
d = datetime.datetime(2022,1,1)
d = d.replace(year = 2023)
print(d)
replaceメソッドを使う方法があります。
使い方はdatetimeオブジェクト.replaceの引数に、変更したい項目 = 値を指定します。
使い方はdatetimeオブジェクト.replaceの引数に、変更したい項目 = 値を指定します。

実行結果です。年の値だけが更新されていることが確認できます。
#python
import datetime
d = datetime.datetime(2022,1,1)
d = d.replace(year = 2023)
d = d.replace(month = 2)
d = d.replace(day = 3)
d = d.replace(hour = 4)
d = d.replace(minute = 5)
d = d.replace(second = 6)
d = d.replace(microsecond = 7)
print(d)
他の値も更新してみます。年、月、日、時、分、秒、マイクロ秒をそれぞれ変更すると、

図のようにそれぞれの値を更新できます。

Python操作方法、関数・メソッドリファレンス
使用用途別にまとめたPythonリファレンスページです。
初期準備、基本概念
ダウンロード、インストール、起動
ShellとEditor、保存、実行
保存したPythonの起動
コメント、docstring、行またぎ
コメント、...
コメント