Overview
...
DateTimeOffset Calendar myCalendar.AddTimeSpan(dateTime: DateTimeOffset, duration: string)
Arguments
Returns
...
Remarks
This method adds the given duration in business hours. If just need to add duration and find next business date time, please use Calendar.GetDateTime method instead.
In addition to ISO-8601 duration format, this method also supports the begin end specifiers for time periods. For example 'P0BD' means begin of the day and 'P0ED' means end of the day.
BD: Begin of the day, DE: End of the day, MB: Begin of the month, ME: End of the month, YB: Begin of the year, YE: End of the year.
P2BY: Adds 2 year to current date and rollbacks to beginning of the year
P1M2BD: Adds 1 month and 2 days to current date and rollbacks to beginning of the day
P1M2ED: Adds 1 month and 2 days to current date and forwards to end of the day
Example
Using duration format
Code Block | ||
---|---|---|
| ||
// Adds 1 month, 1 day, 2 hour
var newDate = $Calendar.StandardCalendar.AddTimeSpan($Calendar.Today, 'P1M1DT2H'); |
Example
Using time span format
Code Block | ||
---|---|---|
| ||
// Adds exactly 1 day, 2 hours, 30 minutes and 45 seconds to the current time. var newDate = $Calendar.StandardCalendar.AddTimeSpan($Calendar.Today, '1.02:30:45'); var newDate |
Warning |
---|
Duration This method adds the duration in business hours and may skip non-business dates while adding duration. |
Example
For 09:00-18:00 business hours, adding 2 hours to 17:00 results next day 10:00 not 09:00
Code Block | ||
---|---|---|
| ||
var nextDate = $Calendar.StandardCalendar.AddTimeSpan($Calendar.TodayDateTimeOffset.parse('2023-02-08T17:00'), 'P1DT2HPT2H'); |
Examples
Code Block | ||
---|---|---|
| ||
//Adds exactly 1 day, 2 hours, 30 minutes and 45 seconds to the current time. // nextDate will be set to '2020-02-09T10:00' |
Example
Adds exactly 1 day, 2 hours, 30 minutes and 45 seconds to the current time.
Code Block | ||
---|---|---|
| ||
var newDate = $Calendar.StandardCalendar.AddTimeSpan($Calendar.Today, '1.02:30:45'); var newDate = $Calendar.StandardCalendar.AddTimeSpan($Calendar.Today, 'P1DT2H'); |