...
Arguments
DateTimeOffset dateTime
Specifies the base date Date time value .to added to
string duration
Returns
...
Remarks
Please make sure that you are using the right calendar object, since adding time is related with your calendar of choice. You can have more info on Calendar definitions by checking the $Calendar object.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.
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 1 day, 2 hours, 30 minutes and 45 seconds to the current time.
var newDate = $Calendar.StandardCalendar.AddTimeSpan($Calendar.Today, '1.02:30:45'); |
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.AddTimeSpan(DateTimeOffset.parse('2023-02-08T17:00'), 'PT2H');
// nextDate will be set to '2020-02-09T10:00' |
Example
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 = $Calendar.StandardCalendar.AddTimeSpan($Calendar.Today, 'P1DT2H'); |
See Also
- Calendar.Add
- Calendar.Subtract
- Relative+Date
- Relative Date