There are no plans to remove addtodate
. However, the datetime
, duration
, and calendarDuration
data types are recommended instead. The
datetime
data type provides flexible date and time formats, storage out
to nanosecond precision, and properties to account for time zones and daylight saving time.
You can add lengths of time to datetime
values by using
duration
values (for hours, minutes, and seconds) or
calendarDuration
values (for calendar years, quarters, months, weeks,
or days).
For example, convert a serial date number to a datetime
value. Then
add an array of hours, in 4-hour increments, by using the hours
function to create an array of duration
values. The
result is an array of datetime
values.
d = 1x4 datetime array
01-Jan-2022 00:00:00 01-Jan-2022 04:00:00 01-Jan-2022 08:00:00 01-Jan-2022 12:00:00
Add 3 calendar months and 2 calendar weeks to a datetime
value that
represents January 1, 2022, 12:00 p.m. by using the calmonths
and calweeks
functions to create
calendarDuration
values. The result is a datetime
value that represents April 15, 2022, 12:00 p.m.
d = datetime
15-Apr-2022 12:00:00