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.
Rainbird uses the daysBetween expression to calculate how many days there are between date instances. Rainbird will return the result of the expression as a number.
The next couple of tabs will demonstrate how to create a map that will use the daysBetween expression in a map that will calculate how many days the user has until a project deadline. The map will count the amount of days between the date the query is run on, and a project deadline date the user will input at runtime.
Figure 1: Example rule using the daysBetween expression
Create the following concepts
1 string concept – ‘Person’
1 date concept – ‘Date’ (which will be entered by the user at runtime )
1 number concept – ‘Days remaining’
Now create relationships to link the concepts, as shown in figure 2:
Figure 2: Concepts linked with relationships
- The daysBetween expression will sit on a rule on the ‘has days remaining‘ relationship
- The ‘has deadline‘ relationship will be used in a condition on the rule on the ‘has days remaining‘ relationship, and will cause Rainbird to prompt the user to select a date from a calendar that will pop up while completing the query
Now that the map’s concepts and relationships have been created, we can build the map’s rule.
The rule will use one condition, and one expression, where the daysBetween function will sit. The expression will also use the today() function to capture the date the query is run on.
Open up the ‘has days remaining’ relationship, click ‘add rule’, select ‘add condition’ and add the ‘%S has deadline %DEADLINE’ relationship as a condition of the rule.
Next, click ‘add expression’, and type in the expression ‘ daysBetween(today(), %DEADLINE). The expression tells Rainbird to count the days between the date the query is run on (today()) and the date the user previously entered (%DEADLINE).
In the assign variable to expression box, “%O” is entered, so Rainbird will return the value of the expression as the object of the ‘%PERSON has days remaining %DAYS_REMAINING’ relationship.
Figure 3: Building the rule
Now, the query is ready to be used.
If we were to run the query on the 28th of February 2021 (2021-02-28 ), and entered March the 7th 2021 (2021-03-07) as the project deadline, Rainbird would calculate that there are 11 days between the dates:
Figure 4: Query result
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.
Rainbird uses the weeksBetween expression to calculate how many weeks there are between date instances. Rainbird will return the result of the expression as a number.
The next couple of tabs will demonstrate how to create a map that will use the weeksBetween expression to calculate how many weeks there are until Christmas Day 2021 from the date the query is run on.
Figure 5: Example rule using the weeksBetween expression
Create the following concepts:
1 string concept – ‘Person’
1 number concept – ‘Christmas’
Now, link the concept with the relationship ‘weeks till christmas’:
Figure 6: Concepts and relationships
- The weeksBetween expression will be used in a rule on the ‘weeks till christmas’ relationship
- The end user will not have to input a date, as the dates Rainbird will count the mounts between (today’s date and Christmas) will be specified in the expression
Now that the map’s concepts and relationship have been created, we can build the map’s rule.
The rule will use one expression, where the weeksBetween function will sit. The expression will also use the today() function to capture date at which the query is run on.
Open up the ‘weeks till christmas’ relationship, click ‘add rule’, select ‘add expression’ and type in the expression ‘ weeksBetween(today(),2021-12-25). The expression tells Rainbird to count the weeks between the date the query is run on (today()) and Christmas Day (2021-12-25).
In the assign variable to expression box, “%O” is entered, so Rainbird will return the value of the expression as the object of the ‘%PERSON weeks till christmas %CHRISTMAS’ relationship.
Figure 7: Building the rule
IIf we were to run the query on the 24th of February 2021 (2021-02-24), Rainbird would calculate that there are 43 weeks until Christmas:
Figure 8: Query result
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.
Rainbird uses the monthsBetween expression to calculate how many months there are between date instances. Rainbird will return the result of the expression as a number.
The next couple of tabs will demonstrate how to create a map that will use the monthsBetween expression in a rule that will calculate how many months are left until a baby is due. The map will count the months between the date the query is run on, and a due date the user will input at runtime.
Figure 9: Example rule using the monthsBetween expression
Create the following concepts:
1 String Concept – ‘Person’
1 Date Concept – ‘A Date’
1 Number concept – ‘Months remaining’
Now create relationships to link the concepts, as shown in figure 10:
Figure 10: Concepts and relationships
- The monthsBetween expression will sit on a rule on the ‘has months remaining‘ relationship
- The ‘has due day‘ relationship will be used in a condition on the rule on the ‘has months remaining‘ relationship, and will cause Rainbird to prompt the user to select a date from a calendar that will pop up while completing the query
Now that the map’s concepts and relationships have been created, we can build the map’s rule.
The rule will use one condition, and one expression, where the monthsBetween function will sit. The expression will also use the today() function to capture the date the query is run on.
Open up the ‘has months remaining’ relationship, click ‘add rule’, select ‘add condition’ and add the ‘%S has due date %A_DATE’ relationship, changing the ‘%A_DATE’ object to ‘%DUE’, as a condition of the rule.
Next, click ‘add expression’, and type in the expression ‘ monthsBetween(today(), %DUE). The expression tells Rainbird to count the months between the date the query is run on (today()) and the date the user previously entered (%DUE).
In the assign variable to expression box, “%O” is entered, so Rainbird will return the value of the expression as the object of the ‘%PERSON has months remaining %MONTHS_REMAINING’ relationship.
Figure 11: Building the rule
If we were to run the query on the 28th of February 2021 (2021-02-28 ), and entered November the 3rd 2021 (2021-11-93) as the due date, Rainbird would calculate that there are 8 months between the dates:
Figure 12: Query result
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.
Rainbird uses the yearsBetween expression to calculate how many years there are between date instances. Rainbird will return the result of the expression as a number.
The next couple of tabs will demonstrate how to create a map that will use the yearsBetween expression to calculate how many years have passed since the beginning of the millennium. The map will count the amount of years between the date the query is run on, and a year that will be specified within the expression (2000).
Figure 13: Example rule using the yearsBetween expression
Create the following concepts:
1 string concept – ‘Person’
1 number concept – ‘Years Between’
Now link the concepts together with a relationship, “has years between”, as shown in figure 14:
Figure 14: Concepts linked with relationship
- The yearsBetween expression will sit on a rule on the “has years between” relationship. The user will not have to input a date, as the dates Rainbird will count the years between will be specified in the expression.
Now that the map’s concepts and relationship have been created, we can build the map’s rule.
The rule will use one expression, where the yearsBetween function will sit. The expression will also use the today() function to capture the date at which the query is run on.
Open up the ‘has years between’ relationship, click ‘add rule’, select ‘add expression’ and type in the expression ‘ yearsBetween(today(), 2000-01-01)‘. The expression tells Rainbird to count the years between the date the query is run on (today()) and the date the world entered a new millenium (2000-01-01).
In the assign variable to expression box, “%O” is entered, so Rainbird will return the value of the expression as the object of the ‘%PERSON has years between %YEARS_BETWEEN’ relationship.
Figure 15: Building the rule
Now, the query is ready to be used.
If we were to run the query on the 24th of February 2021 (2021-02-24), Rainbird would calculate that 21 years have passed since the year 2000:
Figure 16: Query Result
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’
The RBLang below will generate the a map that uses the different expressions mentioned in the article. Click on ‘Export .rbird’ to download the knowledge map, or ‘copy RBLang’ and paste the code directly into Rainbird.
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.