Time and Date Expressions – daysBetween / weeksBetween / monthsBetween / yearsBetween

daysBetween / weeksBetween / monthsBetween / yearsBetween

In Rainbird, concepts can be ‘date’ concepts.  Date concepts should be used when a date will be either input into or output by Rainbird. Dates in Rainbird are formatted as YYYY-MM-DD (e.g. 1st of March 2021 would be formatted as 2021-03-01).

Rainbird can use date expressions to transform and calculate dates. Date expressions can be combined with other date, transformative and comparative expressions to ‘retrieve’, ‘add’,  ‘subtract’ or ‘compare’ time.

If you want to use the outcome of a date expression’s calculation in further calculations, you will need to create the initial date expression on the relationship between the date concept that holds the date concept instances that will be used in the expression, and a number concept which the outcome of the expression will be assigned to.

The expressions discussed in this article are used by Rainbird to calculate the days/weeks/months or years between two dates instances that have either been created at runtime or that exist in the knowledge map.

The expressions discussed in this article are:

daysBetween: calculates the number of complete days between two dates
weeksBetween:
 calculates the number of complete weeks (every 7 days) between two dates
monthsBetween: calculates the number of complete months between two dates
yearsBetween: calculates the number of complete years between two dates

The weeks, months, and yearsBetween expressions, if used in calculations, will return less accurate results than if the daysBetween expression is used, because expressions will round up or down a value to the nearest whole day/week/month/year value. For example, if the weeksBetween function was being used to calculate the time between the 1st of January and the 18th of January, Rainbird would round the true value (18 days) up to three weeks (21 days). The rounded value could still be used in further calculations, but the results will be less accurate. The daysBetween would return a more accurate value of ’18 days’.

Click on an expression below for instructions on how to build a rule that uses that expression.

 

When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the daysBetween function, please run the query on the ‘has days remaining’ relationship.

When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the weeksBetween function, please run the query on the ‘weeks till christmas‘ relationship.

When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the monthsBetween function, please run the query on the ‘has months remaining’ relationship.

When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the yearsBetween function, please run the query on the ‘has years between‘ relationship.

IMPORTANT: Time instances need to be formatted as ‘YYYY-MM-DD HH:MM:SS’

Click on the ‘Export.rbird’ button to download the ‘daysBetween’ map used in this example. The knowledge map can then be imported into your Rainbird Studio.

Query and results

Each expression featured in the article can be demoed in the knowledge map by running the query on the relationship mentioned at the end of each individual expression section in the article above.

Article Feedback form
Did you find this article useful?

Version 1.01 – Last Update: 09/03/2021