Time and Date Expressions – secondsBetween / minutesBetween / hoursBetween

secondsBetween / minutesBetween / hoursBetween

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:

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.

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.

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’

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

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.

Article Feedback form
Did you find this article useful?

Version 1.01 – Last Update: 09/03/2021