We're excited to let you know that starting from version 24 of Calculated Attributes, we've introduced two highly anticipated operators:
DATESPAN and DATEDIFF.
These additions fulfill a long-awaited need – precise and efficient date manipulation.
Let's skip to the point.
Their usage is straightforward:
10: DATESPAN STARTDATE ENDDATE INTERVAL
10: DATEDIFF STARTDATE ENDDATE INTERVAL
Simply select the operator, provide the start and end dates to define an interval, and the result will be the duration of the dates or its segment, depending on the chosen operator.
The STARTDATE and ENDDATE parameters are self-explanatory; they define your interval.
They accept values of types Date or DateTime, and their provider could be a constant, an object's attribute, another expression, etc.
The third parameter, INTERVAL, specifies the unit in which you will receive the result. This can be DAYS, MONTHS, YEARS. The default is DAYS.
You can opt for shorthand too- just use D (for Days), M (for Months), or Y (for Years).
Here're some examples:
// Crm.Sales.SalesOrders
10: DATEDIFF ATTRIB:DocumentDate ATTRIB:RequiredDeliveryDate CONST:Days
We have a Sales Order, and this will return the difference between the document date and the required delivery date in days.
Another one:
// Crm.Customers
10: DATESPAN ATTRIB:CreationTime EXP:20 CONST:Months
20: TODAY
And this will display the number of months that have passed (because we're using DATESPAN) since a customer was created.
DATESPAN
The DATESPAN operator is a significant advancement, enabling users to calculate time duration between dates with specified intervals.
It returns the difference between dates as a duration in the specified interval type. The interval is fulfilled when the same date and time is reached in the next interval.
DATEDIFF
The DATEDIFF operator addresses a crucial need for accurate representations of absolute date differences.
It returns the difference between dates as the absolute date difference for the specified interval type
I'm confused what's the difference?
Let's clarify with some examples.
2023-01-01 23:59
2023-01-02 00:01
That's a 2-minute difference. Now, let's consider the days "inside":
How many days do we have? 0 or 1?
DATESPAN will return 0 days because we don't have a period of a whole day.
DATEDIFF will return 1 day because that's the absolute difference.
Let's see another one,
2023-01-01 23:58
2023-01-02 23:58
As you've probably guessed, both operators will return 1 day.
Because,
- DATESPAN: We have a full day.
- DATEDIFF: Similar to the previous case, we're looking at the absolute difference between two days.
With these exciting operators added, beginning from version 24, Calculated Attributes takes a significant leap forward. It meets the needs of professionals across diverse domains, enabling you to explore new opportunities. Update now and unlock the potential of precise date manipulation!
---
More information is available in our official documentation:
https://docs.erp.net/tech/advanced/calculated-attributes/index.html
https://docs.erp.net/tech/advanced/calculated-attributes/operators/datespan.html
https://docs.erp.net/tech/advanced/calculated-attributes/operators/datediff.html
https://docs.erp.net/tech/advanced/calculated-attributes/examples/index.html
0 Comments