Page 1 of 1

Script to calculate the duration between two dates

Posted: 30 Sep 2024 12:47
by Schuller
Hi,

I would like to know if it is possible to script columns that could calculate the duration between two dates and then output that info into a column that would be displayed as age, e.g 2 years 5 months. I would use this in various ways such as for measuring a project duration, life-cycle of various items, how long an asset was held for, tenant move-in, move-out dates and that duration, and so on..

At the moment I'm currently using a duration calculator I found online (https://www.timeanddate.com/date/durationresult.html) and I'm manually placing the results into the comment column but I think automating this by way of XY scripting would be my preferred way to go if its possible, plus it would free up my comment columns for other info.

My thinking is to have "scripted column 1" get its beginning date from the created date and be displayed, e.g. 2024.09.30, then have "scripted column 2" be a manual input column that would be the ending date and hopefully it could have a similar pop-up option like the "touch created" feature of XY's for entry of this ending date, then finally have "scripted column 3" display the duration as age, e.g. 2 years 5 months.

Please let me know if this can be scripted and if so can you please help with this script. I have zero scripting knowledge.


Thanks

2024.09.30 duration screenshot.jpg
2024.09.30 duration screenshot.jpg (89.95 KiB) Viewed 1793 times

Re: Script to calculate the duration between two dates

Posted: 30 Sep 2024 13:01
by highend
Ofc this can be scripted (but not from me, I'm on vacation atm and I would have charged for it anyway)

Re: Script to calculate the duration between two dates

Posted: 30 Sep 2024 14:43
by admin
Interesting task. I added a new function age() to scripting that will make it easy.

Example (next beta v26.40.0303):

Code: Select all

echo age(datediff("2008-08-08", "2024-09-30", ms)); //16 years, 1 month

Re: Script to calculate the duration between two dates

Posted: 02 Oct 2024 06:07
by Schuller
Okay, will look out for this in the next beta release.
By the way, I don't mind paying for custom scripts.

Thanks

Re: Script to calculate the duration between two dates

Posted: 02 Oct 2024 09:26
by admin
It's already published: viewtopic.php?p=224286#p224286