That challenged me, because I would like to have it in the details component as well.
A bit ugly but this is how I solved, to get an age of a person based on his birth date.
I made a new field in the table, in which Birth date is an inputfield. The new field is an equation:
TRUNCATE(DATEDIFF(CURDATE(),{Birth date})/365,0)
I am sure you have a better solution, it is ugly because not every year has 365 days.
Step 3) Create a table rule and add the pipe. The only parameter you need to include is the Datetime parameter and set it to the date field you want to get the age of.
Thank you for these very clear instructions, Tim! Followup question. I have imported a bunch of records, each of which has a DOB value. I’d like to calculate the Age for all of these and the only way I can see to do it is to edit each DOB value individually and set it to itself. Is there a way to trigger the pipe for all records at once?
Thanks, Tim. I created a scheduled task and ran it. Unfortunately, I made a dumb mistake and forgot to look at my data BEFORE running the task. All the Age values have now been set — but I don’t know if it’s because of the task or whether something happened magically overnight that caused them all to be processed for some other reason. (It’s still close enough to Christmas that I’m willing to believe in things happening magically overnight.)
Does a scheduled task target ALL the records in the table? Is that just the way these work?
Yes, scheduled tasks will trigger on every record in a data table that meets the task condition, or all records in a data table if no condition is set.
Displaying age by simply formatting a DOB field is brilliant and works great. But it returns a value including the word “Years”. Is it possible to show simply the number value, without “Years”? If the column is labeled “Age”, and the values are all integers, users will know that the numbers represent years.
@tim.young is it possible to style it like a standard table?
I’d like to do as many of the following as possible:
Fix the output to days only (no months) and remove “days ago” so the column only contains a number
Turn the text red if > 30 days
Stop counting and retain the final value if a record drop down field is marked “Lost” or “Hold”
If the deal is marked “Won” stop counting and set the final value to the difference between “Application Date” and “Close Date”
I’ll probably need to create a new equation field for this in the data table, but that’s fine. Then I can use that field to solve #1.
For context, this is a deal pipeline and the purpose is to track time on the pipeline. So if there is another solution that will achieve the results, that’s fine too.
Are you looking at simply displaying the values dynamically in a custom component, or doing this on the database level?
For 1 and 2, you can create your own helper (with code). I’ll write up something simple and explain, but it’s quite complex.
For 3 and 4 you might need to address this at the database with custom fields, but you can also just display it in the app. Let me know and we’ll be delighted to help.
The key here is that we are using 3 curly braces since we’re responding with HTML.
I’ll try and explain the code a bit:
At the bottom we have 2 functions. One to get the difference in time between 2 dates we pass it. The second, to cover the date from SQL to Javascript.
We created a custom Helper called “james_custom_2” (call it whatever you wish, but be sure to update the custom component to match.
In this custom helper we pass 3 values, the application date, closing date and status. In the rest of the code we first check is the ‘status’ is equal to Won, if yes, it runs its own code. Otherwise, we find the difference and return the values.
The custom component is truly a powerful component that can achieve nearly anything imaginable when it comes to outputting the data. It might however require some coding. But HandlebarsJS is pretty easy.