Rainbird can use time expressions to calculate complete seconds/minutes or hours between two instances.
In Rainbird, time must be formatted in a specific way for expressions to function properly:
- Time expressions require the date/time being used by the expression to be formatted as YYYY-MM-DD HH:MM:SS (e.g. 2021-03-12 10:30:52)
- When using facts involving date concepts, if no time is specified, Rainbird will count time from midnight (e.g. 2021-03-12 00:00:00)
- When using a time instance within an expression the instance needs to be in ‘ ‘ (e.g. minutesBetween(‘2021-12-01 00:16:00’, ‘2021-12-01 00:20:00’)
- When entering a time whilst running a query that will create a string concept fact, ‘ ‘ and seconds are not required (e.g. 2021-03-02 10:00)
- Time expressions are always positive values
- To convert a milliseconds result divide: / 1000 (seconds) / 60 (minutes) / 60 (hours) / 24 (day) / 365 (year). E.g. to convert a now() result from milliseconds to years: now() / 31536000000 (1000x60x60x24x365). This would return the amount of years between the time the query is run and the 1st of January 1970 (see example in today / now article)
The following time expressions allows Rainbird to make further calculations or comparisons with or between time instances:
secondsBetween: calculates the number of complete seconds between two time instances.
minutesBetween: calculates the number of complete minutes months between two time instances.
hoursBetween: calculates the number of complete hours between two time instances.
Click on an expression below for instructions on how to build a rule that uses that expression:
Rainbird uses the secondsBetween expression to calculate how many seconds there are between time instances.
When using the secondsBetween expression, Rainbird will return a number as a result – the amount of seconds between the two time instances
The next couple of tabs will demonstrate how to create a map that will use the secondsBetween expression to work out the amount of seconds between the date and time the user runs the query, and a date that the user will input at runtime.
Figure 1: Example rule using the secondsBetween expression
Create the following concepts:
2 string concepts – ‘Person’ and ‘Time in Numbers’
1 number concept – ‘Seconds Between’ (a string concept could also be used)
Next, create relationships to connect the concepts, as shown in figure 2:
Figure 2: Concepts linked with relationships
- The main rule of the map will sit on the ‘how many seconds from now‘ relationship
- The ‘enter date and time’ relationship will be used as a condition in the rule, which when triggered at runtime will prompt Rainbird to ask the user to enter a date and time they want to count to
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 secondsBetween function will sit. The expression will also use the now() function to capture the time and date at which the query is run.
Open up the ‘how many seconds from now’ relationship, click ‘add rule’, select ‘add condition’ and add the ‘%S enters date and time %TIME_IN_NUMBERS’ relationship as a condition of the rule.
Next, click ‘add expression’, and type in the expression ‘ secondsBetween( now (), %TIME_IN_NUMBERS, ). The expression tells Rainbird to count the seconds between the date and time at which the query is run (now()) and the date and time the user previously entered (%TIME_IN_NUMBERS).
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 how many seconds from now %SECONDS_BETWEEN relationship.
Figure 3: Building the rule
Now, the query is ready to be used.
If we were to run the query on the 3rd of March 2021 at 3pm (2021-03-02 15:00:00), and entered 2021-03-02 15:00:02 as the time we wanted Rainbird to count to, Rainbird would tell us that there are 2 seconds between the two values:
Figure 4: Query result
When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the secondsBetween function, please run the query on the ‘how many seconds from now’ relationship.
Rainbird uses the minutesBetween expression to calculate how many minutes there are between time instances.
When using the minutesBetween expression, Rainbird will return a number as a result – the amount of minutes between the two time instances
The next couple of tabs will demonstrate how to create a map that will use the minutesBetween expression to work out the amount of minutes between the date the user runs the query, and a date that the user will input at runtime.
Figure 5: Example rule using the minutesBetween expression
Create the following concepts:
1 String Concept – ‘Person’
1 Number Concept ‘Minutes Between‘ (we could also use a String Concept)
1 Date Concept – ‘Date’
Next, create relationships to connect the concepts, as shown in figure 6:
Figure 6: We will ask the user to enter a date on ‘what is the date’
- The main rule will sit on the ‘how many minutes since date’ relationship
- The ‘what is the date’ relationship will be used in the rule to make Rainbird ask the user to enter a date at runtime
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 minutesBetween function will sit. The expression will also use the today() function to capture the date (and time as 00:00:00) the query is run on.
Open up the ‘how many minutes since date’ relationship, click ‘add rule’, select ‘add condition’ and add the ‘%S what is the date %DATE’ relationship as a condition of the rule.
Next, click ‘add expression’, and type in the expression ‘ minutesBetween( today(), %DATE ). The expression tells Rainbird to count the minutes between the date and time at which the query is run (today()) and the date and time the user previously entered (%DATE).
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 how many minutes since date %DATE relationship.
Figure 7: Building the rule
Now, the query is ready to be used.
If we were to run the query on the 2nd of March 2021 (2021-03-00:00:00), and entered 2021-03-03 as the date we wanted Rainbird to count to, Rainbird would tell us that there are 1440 minutes (24 hours) between the two values:
Figure 8: Query Result
When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the minutesBetween function, please run the query on the ‘how many minutes since date’ relationship.
Rainbird uses the hoursBetween expression to calculate how many hours there are between time instances.
When using the hoursBetween expression, Rainbird will return a number as a result – the amount of hours between the two time instances
The next couple of tabs will demonstrate how to create a map that will use the hoursBetween expression to work out the number of hours between the date the user runs the query, and a date that is specified inside the expression (in the example, New Years Day 2022).
Figure 9: Example rule using the hoursBetween expressio
Create the following concepts:
1 string concept – ‘Person’
1 number concept – ‘Hours Between’ (we could also use a String Concept)
Next, connect the two concepts with the relationship ‘how many hours till new year’, as shown in figure 9:
Figure 9: Concepts linked with a single relationship
The rule that will use the hoursBetween expression will sit on the ‘how many hours till new year’ relationship, and will require no user input (hence the single relationship).
Now that the map’s concepts and relationship have been created, we can build the map’s rule.
The rule will be made up of an expression, where the hoursBetween function will sit. The expression will also use the today() function to capture the date (and time as 00:00:00) the query is run on.
Open up the ‘how many hours till new year’ relationship, click ‘add rule’, select ‘add expression’ and type in the expression ‘hoursBetween( today(), ‘2022-01-01 00:00:00 ‘). The expression tells Rainbird to count the hours between the time and date at which the query is run (today()) and the date and time we specified in the expression (New Year’s Day – 2022-01-01 00:00:00).
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 how many hours till new year %HOURS_BETWEEN relationship.

Figure 10: Building the rule
Now, the query is ready to be used.
If we were to run the query on the 2nd of March 2021 (2021-03-02 00:00:00), Rainbird would tell us that there are 7320 hours until New Year’s Day:
Figure 11: Query Result
When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the hoursBetween function, please run the query on the ‘how many hours till new year’ 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 can be demoed in the knowledge map by running the query on the relationship mentioned at the end of each individual expression section above.