Script to calculate the duration between two dates

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Schuller
Posts: 184
Joined: 02 May 2023 21:08

Script to calculate the duration between two dates

Post 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 1795 times

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script to calculate the duration between two dates

Post by highend »

Ofc this can be scripted (but not from me, I'm on vacation atm and I would have charged for it anyway)
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 64915
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Script to calculate the duration between two dates

Post 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

Schuller
Posts: 184
Joined: 02 May 2023 21:08

Re: Script to calculate the duration between two dates

Post 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

admin
Site Admin
Posts: 64915
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Script to calculate the duration between two dates

Post by admin »

It's already published: viewtopic.php?p=224286#p224286

Post Reply