hour(now()) /* Output: 11 (When current time was 11:25 AM) */ /* Assume a propety called Date with a current date of June 24, 2022 11:29 AM */ prop("Date").hour() /* Output: 11 */
hour() can be used with other functions such as dateSubtract to change the value of a date, like so:
/* Assume the value of now() is June 24, 2022 11:34 AM */ now().dateSubtract(now().hour(), "hours") /* Output: June 24, 2022 12:34 AM */
This example database groups events in a Renaissance Faire by their time of day – Morning, Afternoon, and Evening. These three options are returned by the Time of Day formula property.
ifs( prop("Date").hour() >= 18, "🌔 Evening", prop("Date").hour() >= 12, "🌤 Afternoon", "🌄 Morning" )
Here, we use a nested if statement to first check if the
hour() value of the Date property is greater than or equal to 18 (which is 6:00 PM in 12-hour time).
If yes, the formula returns “🌔 Evening”.
If not, we then check if the
hour() value is greater than or equal to 12 (noon in 12-hour time).
If yes, the formula returns “🌤 Afternoon”. If no, it returns “🌄 Morning”.
From there, we can set the database view to Group by the output of this formula property: