# Class HelperDateTime OptimaJet.Workflow.Core.Helpers.HelperDateTime Provides utilities for comparing [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime) values, parsing and applying intervals, and truncating [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) values. Namespace: [OptimaJet.Workflow.Core.Helpers](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Helpers/) ```csharp public static class HelperDateTime ``` ## Methods `public static int CompareWithoutSeconds(this DateTime d1, DateTime d2)` Compares two [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime) values without considering any part of either value below the minute. ### Parameters | Name | Type | Description | | --- | --- | --- | | `d1` | `DateTime` | The first value to compare. | | `d2` | `DateTime` | The second value to compare. | ### Returns | Type | Description | | --- | --- | | `Int32` | `0` when the values have equal [DateTime.Date](https://learn.microsoft.com/dotnet/api/system.datetime.date), [DateTime.Hour](https://learn.microsoft.com/dotnet/api/system.datetime.hour), and [DateTime.Minute](https://learn.microsoft.com/dotnet/api/system.datetime.minute) components; otherwise, the result of [DateTime.CompareTo(DateTime)](https://learn.microsoft.com/dotnet/api/system.datetime.compareto#system-datetime-compareto\(system-datetime\)). | `public static TimeSpan GetInterval(string value)` Parses a fixed-duration interval as a [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan). ### Parameters | Name | Type | Description | | --- | --- | --- | | `value` | `String` | The interval to parse. A value that can be parsed as an [int](https://learn.microsoft.com/dotnet/api/system.int32) represents milliseconds. | ### Returns | Type | Description | | --- | --- | | `TimeSpan` | The parsed [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan), or [TimeSpan.Zero](https://learn.microsoft.com/dotnet/api/system.timespan.zero) when `value` is neither an integer nor a valid fixed-duration interval. | ### Exceptions | Type | Description | | --- | --- | | `ArgumentNullException` | Thrown when `value` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). | | `ArgumentException` | Thrown when `value` contains a working-time component. | ### Remarks A fixed-duration interval can combine day, hour, minute, second, and millisecond components in any order. ### Example `"1500"` represents 1,500 milliseconds. Both `"2d 4h 30m"` and `"2 days 4 hours 30 minutes"` represent two days, four hours, and thirty minutes. `public static TimeSpan GetIntervalFor(DateTime oldDateTime, string intervalString)` Calculates the difference produced by applying an interval to a specified [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). ### Parameters | Name | Type | Description | | --- | --- | --- | | `oldDateTime` | `DateTime` | The value from which to calculate the interval difference. | | `intervalString` | `String` | The interval to apply. A value that can be parsed as an [int](https://learn.microsoft.com/dotnet/api/system.int32) represents milliseconds. | ### Returns | Type | Description | | --- | --- | | `TimeSpan` | The adjusted value minus `oldDateTime`, represented as a [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan). | ### Exceptions | Type | Description | | --- | --- | | `ArgumentNullException` | Thrown when `intervalString` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). | | `ArgumentException` | Thrown when `intervalString` contains a working-time component. | | `ArgumentOutOfRangeException` | Thrown when applying the interval produces a value outside the range supported by [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Remarks For a component-based interval, the result can depend on `oldDateTime` because year and month components are applied as calendar adjustments. ### Example Examples of accepted interval strings are `"1500"`, `"1 month 2 days 3 hours"`, and `"1mm 2d 3h"`. `public static TimeSpan GetInterval(this DateTime dateTime, string intervalString)` Calculates the difference produced by applying an interval to `dateTime`. ### Parameters | Name | Type | Description | | --- | --- | --- | | `dateTime` | `DateTime` | The value from which to calculate the interval difference. | | `intervalString` | `String` | The interval to apply. A value that can be parsed as an [int](https://learn.microsoft.com/dotnet/api/system.int32) represents milliseconds. | ### Returns | Type | Description | | --- | --- | | `TimeSpan` | The adjusted value minus `dateTime`, represented as a [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan). | ### Exceptions | Type | Description | | --- | --- | | `ArgumentNullException` | Thrown when `intervalString` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). | | `ArgumentException` | Thrown when `intervalString` contains a working-time component. | | `ArgumentOutOfRangeException` | Thrown when applying the interval produces a value outside the range supported by [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Remarks This extension method is equivalent to [HelperDateTime.GetIntervalFor(DateTime, string)](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Helpers/HelperDateTime/). ### Example Examples of accepted interval strings are `"1500"`, `"1 month 2 days 3 hours"`, and `"1mm 2d 3h"`. `public static DateTime AddIntervalFor(DateTime dateTime, string intervalString)` Adds the components of an interval to a specified [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). ### Parameters | Name | Type | Description | | --- | --- | --- | | `dateTime` | `DateTime` | The value to adjust. | | `intervalString` | `String` | The interval to add. A value that can be parsed as an [int](https://learn.microsoft.com/dotnet/api/system.int32) represents milliseconds. | ### Returns | Type | Description | | --- | --- | | `DateTime` | The adjusted [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Exceptions | Type | Description | | --- | --- | | `ArgumentNullException` | Thrown when `intervalString` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). | | `ArgumentException` | Thrown when `intervalString` contains a working-time component. | | `ArgumentOutOfRangeException` | Thrown when applying the interval produces a value outside the range supported by [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Remarks Nonnumeric intervals can contain year, month, day, hour, minute, second, and millisecond components, which are applied in that order. ### Example `"1500"` adds 1,500 milliseconds. Both `"1 year 2 months 3 days 4 hours 5 minutes 6 seconds 700 milliseconds"` and `"1y 2mm 3d 4h 5m 6s 700ms"` use the supported component formats. `public static DateTime AddInterval(this DateTime dateTime, string intervalString)` Adds the components of an interval to `dateTime`. ### Parameters | Name | Type | Description | | --- | --- | --- | | `dateTime` | `DateTime` | The value to adjust. | | `intervalString` | `String` | The interval to add. A value that can be parsed as an [int](https://learn.microsoft.com/dotnet/api/system.int32) represents milliseconds. | ### Returns | Type | Description | | --- | --- | | `DateTime` | The adjusted [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Exceptions | Type | Description | | --- | --- | | `ArgumentNullException` | Thrown when `intervalString` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). | | `ArgumentException` | Thrown when `intervalString` contains a working-time component. | | `ArgumentOutOfRangeException` | Thrown when applying the interval produces a value outside the range supported by [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Remarks This extension method is equivalent to [HelperDateTime.AddIntervalFor(DateTime, string)](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Helpers/HelperDateTime/). ### Example `"1500"` adds 1,500 milliseconds. Both `"1 year 2 months 3 days 4 hours 5 minutes 6 seconds 700 milliseconds"` and `"1y 2mm 3d 4h 5m 6s 700ms"` use the supported component formats. `public static DateTime SubtractIntervalFor(DateTime dateTime, string intervalString)` Subtracts the recognized components of a nonnumeric interval from a specified [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). ### Parameters | Name | Type | Description | | --- | --- | --- | | `dateTime` | `DateTime` | The value to adjust. | | `intervalString` | `String` | The interval to apply. | ### Returns | Type | Description | | --- | --- | | `DateTime` | The adjusted [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Exceptions | Type | Description | | --- | --- | | `ArgumentNullException` | Thrown when `intervalString` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). | | `ArgumentException` | Thrown when `intervalString` contains a working-time component. | | `ArgumentOutOfRangeException` | Thrown when applying the interval produces a value outside the range supported by [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Remarks A value that can be parsed as an [int](https://learn.microsoft.com/dotnet/api/system.int32) is added to `dateTime` as a millisecond offset. For other values, recognized year, month, day, hour, minute, second, and millisecond components are subtracted in that order. ### Example Both `"1 month 2 days 3 hours"` and `"1mm 2d 3h"` use the supported component formats. An integer can be supplied as `"1500"`; it follows the millisecond-offset behavior described above. `public static DateTime SubtractInterval(this DateTime dateTime, string intervalString)` Subtracts the recognized components of a nonnumeric interval from `dateTime`. ### Parameters | Name | Type | Description | | --- | --- | --- | | `dateTime` | `DateTime` | The value to adjust. | | `intervalString` | `String` | The interval to apply. | ### Returns | Type | Description | | --- | --- | | `DateTime` | The adjusted [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Exceptions | Type | Description | | --- | --- | | `ArgumentNullException` | Thrown when `intervalString` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). | | `ArgumentException` | Thrown when `intervalString` contains a working-time component. | | `ArgumentOutOfRangeException` | Thrown when applying the interval produces a value outside the range supported by [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime). | ### Remarks This extension method is equivalent to [HelperDateTime.SubtractIntervalFor(DateTime, string)](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Helpers/HelperDateTime/); consequently, an integer interval is added as a millisecond offset. ### Example Both `"1 month 2 days 3 hours"` and `"1mm 2d 3h"` use the supported component formats. An integer can be supplied as `"1500"`; it is added as a millisecond offset. `public static TimeSpan Floor(this TimeSpan timeSpan)` Removes the sub-minute portion from a [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan). ### Parameters | Name | Type | Description | | --- | --- | --- | | `timeSpan` | `TimeSpan` | The value to truncate to whole minutes. | ### Returns | Type | Description | | --- | --- | | `TimeSpan` | A [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) whose [TimeSpan.Seconds](https://learn.microsoft.com/dotnet/api/system.timespan.seconds) and [TimeSpan.Milliseconds](https://learn.microsoft.com/dotnet/api/system.timespan.milliseconds) components are zero. | [Previous IWorkflowGenerator](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Generator/IWorkflowGenerator-TSchemeMedium/) [Next HelperEnum](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Helpers/HelperEnum/)