Add one year to date
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Behrooz Daneshian
am 5 Jan. 2023
Kommentiert: Steven Lord
am 5 Jan. 2023
Hi all,
Assume we have a date character='2022-01-05". What is the simplest way to add one year to that?
0 Kommentare
Akzeptierte Antwort
Bora Eryilmaz
am 5 Jan. 2023
Bearbeitet: Bora Eryilmaz
am 5 Jan. 2023
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 Kommentare
Steven Lord
am 5 Jan. 2023
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))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!