Add one year to date
50 次查看(过去 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!