How to return age difference in custom colomn in a certain way

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

How to return age difference in custom colomn in a certain way

Post by Schuller »

I found this in another post somewhere: return datediff(filetime(<cc_item>, "c"), filetime(<cc_item>, "m"), "m");

How to modify it to return the age expressed exactly as this example only: 2 months 27 days. I don't want any further detail like the word age an on so in the return.

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

Re: How to return age difference in custom colomn in a certain way

Post by highend »

?
datediff() returns just a number, you would need to write a function that turns it into "words"
Don added the new age() function for exactly that purpose...
One of my scripts helped you out? Please donate via Paypal

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

Re: How to return age difference in custom colomn in a certain way

Post by Schuller »

Yes, I saw that new age function.

I guess where I'm stuck then and would need help with is the write a function that turns it into "words"

Can you please assist with that

Thanks

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

Re: How to return age difference in custom colomn in a certain way

Post by highend »

??
age() already returns "words"^^
E.g.: 2 months, 27 days
What's wrong with that?
One of my scripts helped you out? Please donate via Paypal

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

Re: How to return age difference in custom colomn in a certain way

Post by Schuller »

When configuring the Custom Column, what do I put in the script section then? I've selected age already.

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

Re: How to return age difference in custom colomn in a certain way

Post by highend »

Code: Select all

return age(datediff(filetime(<cc_item>, "c"), filetime(<cc_item>, "m"), "ms"));
?
One of my scripts helped you out? Please donate via Paypal

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

Re: How to return age difference in custom colomn in a certain way

Post by Schuller »

That works, Thanks!

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

Re: How to return age difference in custom colomn in a certain way

Post by Schuller »

Seems like the duration time is off by one month with XY. When using the duration calculator online, I put Jan 1, 2022, for start date and June 30, 2024, for end date and it formulates 2 years, 6 months. With XY calculating the date difference for the exact same time period, I get 2 years, 5 months. Is there something I can do to modify that script to add this extra month?


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

Re: How to return age difference in custom colomn in a certain way

Post by highend »

No, you would need to calculate it by taking things like leap years & exact length of months into account (if Don can't improve the precision of age() any further or if age() already rounds the result (which I didn't test))...
One of my scripts helped you out? Please donate via Paypal

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

Re: How to return age difference in custom colomn in a certain way

Post by Schuller »

Yeah, I'm not sure this will work for me then. Hopefully it will be improved in future.
Thanks anyway.
Last edited by Schuller on 04 Oct 2024 19:00, edited 1 time in total.

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

Re: How to return age difference in custom colomn in a certain way

Post by admin »

No, the datediff() function knows everything there is to know about leap years and month lengths. The problem here is the requested resolution of age(), and how the function handles this: currently the reminder is *cropped*, not *rounded*. If you go for full resolution the result of echo age(datediff("2022-01-01", "2024-06-30", "ms"), 7); is this: 2 years, 5 months, 28 days, 7 hrs, 56 mins, 6 secs, 0 ms which would clearly round up to 2 years, 6 months.

I will add an option to round the result, and all will be fine.

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

Re: How to return age difference in custom colomn in a certain way

Post by Schuller »

Cool, will look out for it.

Post Reply