MotoHawk DateTime and TimeSpan Math
This block performs math operations on TimeSpan and DateTime objects.
Block ID
DateTime and TimeSpan Math
Library
motohawk_datetime_lib/Date/Time Blocks
Description
This block performs math operations on TimeSpan and DateTime objects. The resulting data type can be TimeSpan or DateTime depending on the operation.
The range for the datetime data type is 0000-01-01 00:00:00 to 4095-12-31 23:59:59 and 999999 microseconds, while the range for the timespan data type is between -4194305 to 4194304 days (exclusive). If the output value goes beyond this limit, the output will saturate.
The Matlab convention is used for the operations. If the result of the operation falls into an invalid date of the month, the result is normalized to the lst of the month (ie, Feb 29th, 2001 -> Feb 28th, 2001).
Examples:
Feb 28th, 2003 + 1 Day = March 1st, 2003
Feb 28th, 2004 + 1 Day = Feb 29th, 2004
Feb 29th, 2004 + 12 Months = Feb 28th, 2005
Feb 28th, 2005 + 1 Month = Mar 28th, 2005
Dec 31st, 2004 - Dec 31st, 2003 = 366 Days
Dec 31st, 2003 - Dec 31st, 2002 = 365 Days
Block Parameters
Parameter Field | Values | IN1 Datatype | IN2 Datatype | OUT Datatype | Comments/Description |
---|---|---|---|---|---|
Operation | DateTime - DateTime | DateTime | DateTime | TimeSpan | Subtract a DateTime from another DateTime. Output is a TimeSpan, and can be negative. |
TimeSpan + TimeSpan | TimeSpan | TimeSpan | TimeSpan | Add a TimeSpan to another TimeSpan. Output is a TimeSpan. | |
TimeSpan - TimeSpan | TimeSpan | TimeSpan | TimeSpan | Subtract a TimeSpan from another TimeSpan. Output is a TimeSpan. | |
DateTime + TimeSpan | DateTime | TimeSpan | DateTime | Add a TimeSpan to a DateTime. Output is a DateTime. | |
DateTime - TimeSpan | DateTime | TimeSpan | DateTime | Subtract a TimeSpan from a DateTime. Output is a DateTime. | |
DateTime + Years | DateTime | int16 | DateTime | Add Years to a DateTime. Output is a DateTime. | |
DateTime + Months | DateTime | int16 | DateTime | Add Months to a DateTime. Output is a DateTime. |