Set Variable Based on Day & Time

Does anyone know how to set a variable based on date/time? I need to take the current date/time and set a variable like {We’re open!} or {We’re closed!} based on normal business operating days/hours.

Hi you can use this variable.
The provided logic uses a switch statement to first check the current day of the week using now' in ddddformat (e.g., "Monday", "Tuesday"). If the day is "Saturday" or "Sunday", it always sets the status to "We’re closed!". For weekdays ("Monday" to "Friday"), it checks the current hour usingnowinH` format (24-hour time without leading zeros). If the hour is between 9 (inclusive) and 17 (exclusive), it sets the status to “We’re open!”; otherwise, it sets the status to “We’re closed!”.

{{switch(formatDate(now; “dddd”); “Monday”; if(formatDate(now; “H”) >= 9 & formatDate(now; “H”) < 17; “We’re open!”; “We’re closed!”); “Tuesday”; if(formatDate(now; “H”) >= 9 & formatDate(now; “H”) < 17; “We’re open!”; “We’re closed!”); “Wednesday”; if(formatDate(now; “H”) >= 9 & formatDate(now; “H”) < 17; “We’re open!”; “We’re closed!”); “Thursday”; if(formatDate(now; “H”) >= 9 & formatDate(now; “H”) < 17; “We’re open!”; “We’re closed!”); “Friday”; if(formatDate(now; “H”) >= 9 & formatDate(now; “H”) < 17; “We’re open!”; “We’re closed!”); “Saturday”; “We’re closed!”; “Sunday”; “We’re closed!”)}}


If you want to test it using a variable I did this

set 62.date to day of week in format dddd
and 62.time to hour in 24 hr format

{{switch(62.date; “Monday”; if(62.time >= 9 & 62.time < 17; “We’re open!”; “We’re closed!”); “Tuesday”; if(62.time >= 9 & 62.time < 17; “We’re open!”; “We’re closed!”); “Wednesday”; if(62.time >= 9 & 62.time < 17; “We’re open!”; “We’re closed!”); “Thursday”; if(62.time >= 9 & 62.time < 17; “We’re open!”; “We’re closed!”); “Friday”; if(62.time >= 9 & 62.time < 17; “We’re open!”; “We’re closed!”); “Saturday”; “We’re closed!”; “Sunday”; “We’re closed!”)}}

Let me know if this is the solution and please set as is @Mike_Fetherling

2 Likes