Date Calculations - Age of an asset

I’m building an asset database and I need to store the age of an asset based on the current date minus the field “Purchase Date” and display it like “5yr 2mth” Any way to do this?

Thanks Rob

Customize the date field column in a table and change output to “age”

See here - https://docs.tadabase.io/categories/manual/article/tables#bkmrk-date-output-format

1 Like

Holy crap that was easy. Thanks.

1 Like

You’re welcome! Lots of little “hidden” features in Tadabase

1 Like

I have a long way to go. I’m coming from MS Access and this is a bit of a learning curve.

How would you display both, so both the age and the asset addition date. You should be able to repeat this field then.

Hi @Peter,

You can add the date/time field to a component more than once. I believe this works with every data component except for a details component.

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.

Hi @Peter,

You could use the Tadabase Date Utilities pipe to get the age.

Step 1) Install the Date Utilities Pipe

Step 2) Add a number field if you want to display just the years, add a text field if you want to display a detailed age with years, months, and 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.

Step 4) Set the number field or text field accordingly.

1 Like

It works beautifully, thanks

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?

Hi @WilliamPorter,

Scheduled tasks!

Pipes can run in a scheduled task giving you the ability to process an entire data table.

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.

image

Maybe @Chem has a JavaScript solution for this?

We have a minor update being rolled out soon that will add custom classes to each part of the field.

You’ll then be able to simply add this CSS to the page:

.tb-age-year-text {
    display: none;
}

I’ll confirm when this is live.

@tim.young I have a curveball on the original question - how would you calculate age in a custom component table?

Here ya go @james :grin:

Impressive! thank you