I missed this one. Thank you!!!
Where does this “Round()” go?
I’m stuck on another formatting issue.
I need to add 1 day to today’s date and set time for 4:00 am.
formatDate(addDays(now(),1,setDatePart(startOfDate(now()), 'hour', 4)),'MMM D, h:mm a') // Sep 25, 2:33 pm
It can be used in a formula. In the above example, the calculation was returning a decimal value (eg. 21.53
) and an integer value was preferred, so the whole formula could be wrapped in the round()
function.
{
"formula": "round(22.83 + 0.14)"
}
It looks like a parenthesis issue again which can get tricky when nesting multiple function calls within each other. You can think of nesting functions within functions kind of like those Russian nesting dolls. Each function needs to have its own parenthesis closed before you can nest it within another function.
addDays(now(),1)
startOfDate( )
setDatePart( , 'hour', 4)
formatDate( ,'MMM D, h:mm a')
Which ultimately gets you:
formatDate(setDatePart(startOfDate(addDays(now(),1)), 'hour', 4),'MMM D, h:mm a')
The expression feature is now available in beta as a native Rule Engine feature! If you’re part of our beta program, you should be able to see the post in the beta category.
If you’re not part of the beta program, you can use the /math
endpoint noted above or send a PM to @support with your math/date expression use-case and we can get you added to the beta group!
Using a variable that contains an array will no longer “pretty print” arrays as the new expression feature enables custom formatting.*
I am making an API call to openweather to get the sunset using context.variable.response.current.sunset
that returns in seconds. 1664586776.
I want to convert that to ‘h:mm a’ but for it to convert correctly it needs to be in milliseconds. Is there a way to either convert the response from openweather to result in millisecond or to format the conversion to use seconds.
In the reference documents I see x
for milliseconds and X
for seconds but I don’t know what that format would look like. I’m currently using the math lab http with formatDate($sunset, 'h:mm a')
Is $sunset
referring to the stored API response (timestamp in seconds) in your second formula?
You could multiply it by 1000 either when saving it to the $sunset
variable or if the variable is stored in seconds, you could multiply it by 1000 when using the variable.
Adjusting when saving:
Set $sunset:
$context.reponse.data.current.sunrise * 1000
-OR-
Adjusting when using:
formatDate($sunset * 1000, 'h:mm a')
Yes and that worked! Thank you!
Just a reminder that the expression feature is available in beta! If anyone wants to join the beta and help test, shoot a PM to @support
Update : Math and Date functions are now available publicly as part of our native Rule Expressions feature!
Here’s a quick demo going through some of the features including math with variables, logic, date formatting, and date math. I was moving quick to stay under a minute, but feel free to pause the video if needed!
Love the Tap to Evaluate! Much easier than a test rule set to run the next minute, and then . . . waiting.
Math and Date Expressions are now available! Thanks to everyone who voted for this feature and a special thanks to those of you who helped beta test! You can find details on the release in the following thread:
https://community.sharptools.io/t/math-date-expressions/10368?u=josh