Add one year to date
19 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
Assume we have a date character='2022-01-05". What is the simplest way to add one year to that?
0 件のコメント
採用された回答
Bora Eryilmaz
2023 年 1 月 5 日
編集済み: Bora Eryilmaz
2023 年 1 月 5 日
You can use the datetime and years commands to do what you want:
date = '2022-01-05';
d = datetime(date)
d1 = d + years(1)
string(d1)
2 件のコメント
Steven Lord
2023 年 1 月 5 日
In this case you probably want to use calyears (to add 1 calendar year) instead of years (which adds 365.2425 days.)
date = '2022-01-05';
d = datetime(date)
d1 = d + years(1)
d2 = d + calyears(1)
daysPerYearDuration = days(years(1))
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!